Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

1

Dr. A.P.J. Abdul Kalam Technical University


Uttar Pradesh, Lucknow

Web Technology Lab File


KCS 652

Submitted to: Submitted by:


Mr. Hakim Singh Prashant Saxena
(Assistant professor) (1814310147)

Department of Computer Science and Engineering


I.M.S Engineering College, Ghaziabad, UP
(Affiliated to Dr. A.P.J Abdul Kalam Technical University, Uttar
Pradesh, Lucknow)

Prashant Saxena 1814310147 CSE 03


2

WEB TECHNOLOGY LAB FILE


Submitted in the partial fulfilment of the Requirements for the award of

Degree of Bachelor of Technology in Computer Science and Engineering

Submitted by:
Prashant Saxena
1814310147

Submitted to:
Mr. Hakim Singh
(Assistant Professor)

Department of Computer Science and Engineering

IMS ENGINEERING COLLEGE

GHAZIABAD (UP)

Prashant Saxena 1814310147 CSE 03


3

Web Technology Lab

Subject Code: KCS 652


List of Programs
PROGRAMS Date Remark Sign

1. Write a java program to find the factorial of n.


2. Write a java program that will concatenate 2
strings and return the result. The result should be
in lowercase.
Note: If the concatenation creates a double-char,
then one of the characters need to be omitted.
3. Given a string, return a new string made of 'n'
copies of the first 2 chars of the original string
where 'n' is the length of the string.
4. Write a Java program that will return the first half
of the string, if the length of the string is even. It
should return null for odd length string.
5. Write a program that accepts a string and returns
a new string without the first and last character of
the input string.
6. Given 2 strings, and b, return a string of the form
short-long-short with the shorter string on the
outside and the longer string on the inside.
The strings will not be the same length, but they
may be empty (length 0).
7. Given a string, if the first or last chars are 'x',
return the string without those 'x' chars,
otherwise return the string unchanged.
8. Write a Java program that accepts a string (with in
it). The program should return a new string in
which the following characters are removed -,the
characters that are to the left and right of *.
9. Given two strings, a and b, print a new string
which is made of the following combination-first
character of a, the first character of b, second
character of a, second character of b and so on.
Any characters left, will go to the end of the
result.

Prashant Saxena 1814310147 CSE 03


4

10. Write a java program to count the non-repeated


digit in given integer value.
11. Write a java program to count number of prime in
a given range.
12. Write a Java program to print nth number of
Fibonacci series.
13. Write a java program to check whether given
string is palindrome or not.
14. Write a java program to calculate the weight of a #
given string, take A=a=1, B=b=2 and so on.
15. Write a java program to calculate the sum of #
digits in cylindrical Order. For ex: input: 12345
16. Write a java program to print the most Frequent
Digit in given 4 numbers.
17. Given the following table containing information
about employees of an organization, develop a
small java application, which accepts employee id
from the command prompt and displays the
following details as output:
18. Resume using HTML & CSS
19. Student Registration form

Prashant Saxena 1814310147 CSE 03


5

PROGRAM 1
Write a java program to find the factorial of n.

PROGRAM:
import java.util.Scanner;
class ques1 {
public static void main(String args[])
{
int n, c, f = 1;
System.out.print("n : ");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if (n < 0)
System.out.println("-ve num");
else
{
for (c = 1; c <= n; c++)
f = f*c;
System.out.println("Factorial : "+f);
}
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


6

PROGRAM 2
Write a java program that will concatenate 2 strings and return the result. The result should be in
lowercase.
Note: If the concatenation creates a double-char, then one of the characters need to be omitted.

PROGRAM:
import java.util.Scanner;
public class ques2
{
public static void main(String[] args)
{
String a, b, c;
Scanner s = new Scanner(System.in);
System.out.print("A : ");
a = s.nextLine();
System.out.print("B : ");
b = s.nextLine();
ques2 obj = new ques2();
c = obj.concat(a, b);
System.out.println("A+B : " +c.toLowerCase());
}
String concat(String x, String y)
{
String z;
z = x + " " + y;
return z;
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


7

PROGRAM 3
Given a string, return a new string made of 'n' copies of the first 2 chars of the original string
where 'n' is the length of the string.

PROGRAM:
import java.util.Scanner;
public class ques3 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
String next="";
System.out.println("Enter the string");
String abc= sc.nextLine();
int lenght =abc.length();
if(lenght<=1){
next=abc;

}
else{
for (int i=0;i<lenght;i++){
next=next+abc.charAt(0)+abc.charAt(1);
}
}
System.out.print(next);
sc.close();

OUTPUT:

Prashant Saxena 1814310147 CSE 03


8

PROGRAM 4
Write a Java program that will return the first half of the string, if the length of the string is even. It
should return null for odd length string.

PROGRAM:
import java.util.Scanner;

public class ques4 {

public static void main(String[] args) {


Scanner sc= new Scanner(System.in);
String a= sc.nextLine();

String b=null;
int lenght=a.length();
int n=lenght/2;
if(lenght%2==0)
{ b="";
for(int i=0;i<n;i++){
b=b+a.charAt(i);

}
System.out.print(b);
}
else
System.out.println(b);
sc.close();
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


9

PROGRAM 5
Write a program that accepts a string and returns a new string without the first and last character
of the input string.

PROGRAM:
import java.util.Scanner;
class ques5 {
public static String
removeFirstandLast(String str)
{
str = str.substring(1, str.length() - 1);
return str;
}
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
String str= sc.nextLine();
System.out.print(
removeFirstandLast(str));
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


10

PROGRAM 6
Given 2 strings, and b, return a string of the form short-long-short with the shorter string on the
outside and the longer string on the inside.
The strings will not be the same length, but they may be empty (length 0).

PROGRAM:
import java.util.Scanner;
class ques6 {
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
if(a.length() > b.length())
System.out.println(b+a+b);
else
System.out.println(a+b+a);
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


11

PROGRAM 7
Given a string, if the first or last chars are 'x', return the string without those 'x' chars, otherwise
return the string unchanged.

PROGRAM:
import java.util.Scanner;

public class ques7 {


public static String withoutX(String str) {
int len = str.length();
String word = "";
for (int i = 0; i < len; i++) {
if (i == 0 && str.charAt(0) != 'x') {
word += str.charAt(0);
}
else if (i > 0 && i < len-1) {
word += str.charAt(i);
}
else if (i == len-1 && str.charAt(len-1) != 'x') {
word += str.charAt(len-1);
}
}
return word;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str= sc.nextLine();
System.out.println(withoutX(str));

}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


12

PROGRAM 8
Write a Java program that accepts a string (with in it). The program should return a new string in
which the following characters are removed -,the characters that are to the left and right of *.

PROGRAM:
public class ques8
{
public static void main(String[] args) {
String s="Pras*hant";
int i=0, ind=-1;
char ch='*';
for(i=0;i<s.length();i++) {
if(ch==s.charAt(i)) {
ind=i;
break;
} else {
continue;
}
}
for(i=0;i<s.length();i++) {
if(i==ind) {
continue;
} else {
System.out.print(s.charAt(i));
}
}
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


13

PROGRAM 9
Given two strings, a and b, print a new string which is made of the following combination-first
character of a, the first character of b, second character of a, second character of b and so on.
Any characters left, will go to the end of the result.

PROGRAM:
import java.util.Scanner;
public class ques9 {
public static String merge(String s1, String s2)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < s1.length() || i < s2.length(); i++) {
if (i < s1.length())
result.append(s1.charAt(i));
if (i < s2.length())
result.append(s2.charAt(i));
}

return result.toString();
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.next();
System.out.println(merge(s1, s2));
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


14

PROGRAM 10
Write a java program to count the non-repeated digit in given integer value.

PROGRAM:
import java.util.Scanner;
public class ques10 {
public static void NonRepeating(int a[],int n) {
int count;
System.out.println("output");
for(int i=0;i<n;i++) {
count=0;
for (int j = 0; j < n; j++) {
if(a[i]==a[j] && i!=j)
count++;
}
if(count==0)
System.out.print(a[i]+" ");
}
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);

System.out.println("num of elements");
int size=sc.nextInt();
int[] a=new int[100];
System.out.println("input");
for(int i=0;i<size;i++)
{
a[i]=sc.nextInt();
}
NonRepeating(a,size);
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


15

PROGRAM 11
Write a java program to count number of prime in a given range.

PROGRAM:
import java.util.Scanner;
public class ques2
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int start = sc.nextInt();
int end = sc.nextInt();
int count;
for(int i = start ; i <= end ; i++)
{
count = 0;
for(int j = 1 ; j <= i ; j++)
{
if(i % j == 0)
count = count+1;
}
if(count == 2)
System.out.println(i);
}
sc.close();
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


16

PROGRAM 12
Write a Java program to print nth number of Fibonacci series.

PROGRAM:
import java.util.Scanner;

public class ques3 {


public static void main(String[] args) {
int n, num1 = 0, num2 = 1;
Scanner s = new Scanner(System.in);
System.out.print("n : ");
n = s.nextInt();
int nth = fib(n);
System.out.println( nth);
}
private static int fib(int num) {
if (num == 1 || num == 2) {
return 1;
}
return fib(num - 1) + fib(num - 2);
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


17

PROGRAM 13
Write a java program to check whether given string is palindrome or not.

PROGRAM:
import java.util.*;
class PalindromeExample2
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner(System.in);
original = in.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("palindrome.");
else
System.out.println("NOT palindrome.");
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


18

PROGRAM 14
Write a java program to calculate the weight of a given string, take A=a=1, B=b=2 and so on.

PROGRAM:

OUTPUT:

Prashant Saxena 1814310147 CSE 03


19

PROGRAM 15
Write a java program to calculate the sum of digits in cylindrical Order.

PROGRAM:

OUTPUT:

Prashant Saxena 1814310147 CSE 03


20

PROGRAM 16
Write a java program to print the most Frequent Digit in given 4 numbers.

PROGRAM:
import java.util.Scanner;
public class ques16 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int cnt[] = new int[4]; //only 4 inputs
int i;
for (i = 0; i <4; i++){
int n = input.nextInt();
cnt[--n]++;
}
int max = 0;
for (int n : cnt){
if (max < n){
max = n;
}
}
System.out.println("Frequent Digit : ");
for (i = 0; i < cnt.length; i++){
if (cnt[i] == max){
System.out.println(i + 1);
}
}
}
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03


21

PROGRAM 17
Given the following table containing information about employees of an organization, develop a
small java application, which accepts employee id from the command prompt and displays the
following details as output:

Prashant Saxena 1814310147 CSE 03


22

PROGRAM:

import java.util.*;
public class ques17 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int empno[] = {1001, 1002, 1003, 1004, 1005, 1006, 1007};
String empname[] = {"Ashish", "Sushma", "Rahul", "Chahat", "Ranjan", "Suman", "Tan
may"};
String dept[] = {"R&D", "PM", "Acct", "Front Desk", "Engg", "Manufacturing", "PM"}
;
char descode[] = {'e', 'c', 'k', 'r', 'm', 'e', 'c'};
int basic[] = {20000, 30000, 10000, 12000, 50000, 23000, 29000};
int hra[] = {8000, 12000, 8000, 6000, 20000, 9000, 12000};
int it[] = {3000, 9000, 1000, 2000, 20000, 4400, 10000};
int designcode[] = {'e', 'c', 'k', 'r', 'm'};
String designation[] = {"Engineer", "Consultant", "Clerk", "Receptionist", "Manage
r"};
int da[] = {20000, 32000, 12000, 15000, 40000};
int emp = sc.nextInt();
int index = 0, index1 = 0;
for (int i = 0; i < 7; i++) {
if (emp == empno[i]) {
index = i;
break;
}
}
int dcode = descode[index];
for (int i = 0; i < 5; i++) {
if (dcode == designcode[i]) {
index1 = i;
}
}
System.out.println("Employee No. " + empno[index]);
System.out.println("Employee Name: " + empname[index]);
System.out.println("Department: " + dept[index]);
System.out.println("Designation Code: " + designation[index1]);
System.out.println("Salary: " + (basic[index] + hra[index] + da[index1] - it[index
]));

}
}

Prashant Saxena 1814310147 CSE 03


23

OUTPUT:

Prashant Saxena 1814310147 CSE 03


24

PROGRAM 18
Resume using HTML & CSS.

PROGRAM:
//Home Page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="Resume using frame tag.">
<title>Resume</title>
</head>
<body>
<iframe src="/Assignments/ass3/res.html" width="85%" height="235"></iframe>
<iframe src="/Assignments/ass3/pic.html" width="14%" height="235" align="right"></ifra
me>
<iframe src="/Assignments/ass3/navi.html" width="14%" height="500" align="left"></ifra
me>
<iframe src="/Assignments/ass3/score.html" width="85.35%" height="500" align="left" na
me="front"></iframe>
</body>
</html>
//Title frame
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body >

<marquee direction="alternate" scrollamount="20" Book Antiqua" behavior="alternate"><h


1 align="left">RESUME &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp&nbsp &nbsp&nbsp &nbs
p&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&
nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nb
sp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp RESUME &nbsp &nbsp &nbsp &nbsp &nbsp
&nbsp &nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &
nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nb
sp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp
RESUME &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&n
bsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbs
p &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp
&nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp RESUME &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &n
bsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbs
p&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&

Prashant Saxena 1814310147 CSE 03


25

nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp&nbsp &nbsp RESUME</h1></


marquee>
</body>
</html>
//Picture Frame
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body align="center" style="background-color:#cccc00;">
<img src="/img/resume_pic.png" alt="Error !! in loading image." width="125"><br>
Prashant Saxena<br>
dpspra1999@gmail.com<br>
+917060850349
</body>
</html>
//Navigation Frame
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="navigation pannel">
<title>navigation</title>
<style>
table, th, td {
border: 1px solid white;
}

th, td {
padding: 15px;
}
</style>
</head>
<body>

<table align="left" border=1 cellspacing="0" style="width:100%" height="488px">


<tbody>
<tr>
<td align="center"><a href="/Assignments/ass3/navi/objective.html" target=
"_self" style="color: black;">Objective</a></td>
</tr>
<tr>
<td align="center"><a href="/Assignments/ass3/navi/qualification.html" tar
get="_self" style="color: black;">Qualification</a></td>
</tr>
<tr>
Prashant Saxena 1814310147 CSE 03
26

<td align="center"><a href="/Assignments/ass3/navi/projects.html" target="


_self" style="color: black;">projects</a></td>
</tr>
<tr>
<td align="center"><a href="/Assignments/ass3/navi/languages.html" target=
"_self" style="color: black;">Languages</a></td>
</tr>
<tr>
<td align="center"><a href="/Assignments/ass3/navi/subjects.html" target="
_self" style="color: black;">Subjects</a></td>
</tr>
<tr>
<td align="center"><a href="/Assignments/ass3/navi/personal.html" target="
_self" style="color: black;">Personal Details</a></td>
</tr>

</tbody>
</table>
</body>
</html>
//Score Frame
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table, th, td {
border: 1px solid black;
}

th, td {
padding: 15px;
}
</style>

</head>
<body>
<br><br><br><br><br>
<table align="center" border=1 cellspacing="0" style="width:80%" height="58%">
<thead>
<th>Degree</th>
<th>Universety / Board</th>
<th>College / School</th>
<th>Percentage</th>
<th>Year</th>
</thead>

Prashant Saxena 1814310147 CSE 03


27

<tbody>
<tr>
<td>B. Tech</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>XII</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>X</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table><br><br><br><br><br><br><br><br>
</body>
</html>

OUTPUT:

Prashant Saxena 1814310147 CSE 03


28

PROGRAM 17
Student Registration form

PROGRAM:
//HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/File/ques19.css">
</head>
<body>
<form>
<div class="container">
<center> <h1> Student Registeration Form</h1> </center>
<hr>
<label> Firstname </label>
<input type="text" name="firstname" placeholder= "Firstname" size="15" required />
<label> Middlename: </label>
<input type="text" name="middlename" placeholder="Middlename" size="15" required />
<label> Lastname: </label>
<input type="text" name="lastname" placeholder="Lastname" size="15"required />
<div>
<label>
Course :
</label>

<select>
<option value="Course">Course</option>
<option value="BCA">BCA</option>
<option value="BBA">BBA</option>
<option value="B.Tech">B.Tech</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
<option value="M.Tech">M.Tech</option>
</select> &nbsp&nbsp&nbsp
<label>
Branch :
</label>

<select>
<option value="CS">CS</option>
<option value="EC">EC</option>
<option value="EN">EN</option>
<option value="ME">ME</option>
<option value="IT">IT</option>
<option value="BT">BT</option>

Prashant Saxena 1814310147 CSE 03


29

<option value="CE">CE</option>
</select>
</div>
<div>
<label>
Gender :
</label><br>
<input type="radio" value="Male" name="gender" checked > Male
<input type="radio" value="Female" name="gender"> Female
<input type="radio" value="Other" name="gender"> Other

</div>
<label>
Phone :
</label>
<input type="text" name="country code" placeholder="Country Code" value="+91" size="2"/>

<input type="text" name="phone" placeholder="phone no." size="10"/ required>


Current Address :
<textarea cols="80" rows="5" placeholder="Current Address" value="address" required>
</textarea>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>

<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>

<label for="psw-repeat"><b>Re-type Password</b></label>


<input type="password" placeholder="Retype Password" name="psw-repeat" required>
<button type="submit" class="registerbtn">Register</button>
</form>
</body>
</html>
//CSS
body{
font-family: Calibri, Helvetica, sans-serif;

}
.container {
padding: 50px;
}

input[type=text], input[type=password], textarea {


width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
display: inline-block;
border: none;
background: #f1f1f1;
}
Prashant Saxena 1814310147 CSE 03
30

input[type=text]:focus, input[type=password]:focus {
background-color: orange;
outline: none;
}
div {
padding: 10px 0;
}
hr {
border: 1px solid #f1f1f1;
margin-bottom: 25px;
}
.registerbtn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 100%;
opacity: 0.9;
}
.registerbtn:hover {
opacity: 1;
}

OUTPUT:

Prashant Saxena 1814310147 CSE 03

You might also like