Professional Documents
Culture Documents
Web Technology File 2020-21
Web Technology File 2020-21
Submitted by:
Prashant Saxena
1814310147
Submitted to:
Mr. Hakim Singh
(Assistant Professor)
GHAZIABAD (UP)
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:
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:
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:
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;
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:
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:
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:
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;
}
}
OUTPUT:
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:
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:
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:
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:
PROGRAM 12
Write a Java program to print nth number of Fibonacci series.
PROGRAM:
import java.util.Scanner;
OUTPUT:
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:
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:
PROGRAM 15
Write a java program to calculate the sum of digits in cylindrical Order.
PROGRAM:
OUTPUT:
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:
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:
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
]));
}
}
OUTPUT:
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 >
th, td {
padding: 15px;
}
</style>
</head>
<body>
</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>
<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:
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>    
<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>
<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"/>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
}
.container {
padding: 50px;
}
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: