Professional Documents
Culture Documents
Computer Project Part 2 (10-15)
Computer Project Part 2 (10-15)
Computer Project Part 2 (10-15)
Project
2022-23
Name: xxx
Grade: xx
Roll No: xx
ACKNOWLEDGEMENT
String 2: WORD
Output: BWAOLRLD
Divyasha Satapathy 1
Program 10:
import java.util.Scanner;
class Program_10
String s1=sc.next();
String s2=sc.next();
String res="";
if(s1.length()==s2.length())
for(int i=0;i<s1.length();i++)
res=res+s1.charAt(i)+s2.charAt(i);
System.out.println(res);
else
System.out.println("Invalid Input");
Divyasha Satapathy 2
}
Divyasha Satapathy 3
Variable Description Table:
Output:
Divyasha Satapathy 4
Divyasha Satapathy 5
Question 11:
Divyasha Satapathy 6
Program 11:
import java.util.Scanner;
class Program_11
String str=sc.nextLine();
String output_path=str.substring(0,(str.lastIndexOf('\\')+1));
String file_name=str.substring(str.lastIndexOf('\\')
+1,str.lastIndexOf('.'));
String extension=str.substring(str.lastIndexOf('.')+1,str.length());
System.out.println("Extension: "+extension);
Divyasha Satapathy 7
Variable Description Table:
Output:
Divyasha Satapathy 8
Question 12:
Divyasha Satapathy 9
Program 12:
import java.util.Scanner;
class Program_12
String str=sc.nextLine();
String res="";
for(int i=0;i<str.length();i++)
char ch=str.charAt(i);
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
res=res+"@";
else
res=res+ch;
System.out.println(res);
Divyasha Satapathy 10
}
Divyasha Satapathy 11
Variable Description Table:
Output:
Divyasha Satapathy 12
Question 13:
Output: aplictons
Divyasha Satapathy 13
Program 13:
import java.util.Scanner;
class Program_13
String word=sc.next();
int i=0;
String res="";
while(i<word.length())
char ch=word.charAt(i);
if(word.indexOf(ch)!=word.lastIndexOf(ch))
if(i==word.lastIndexOf(ch))
else
Divyasha Satapathy 14
{
res=res+ch;
else
res=res+ch;
i++;
System.out.println(res);
Divyasha Satapathy 15
Variable Description Table:
Output:
Divyasha Satapathy 16
Question 14:
Write a program to declare an array to accept and store five words. Display the number
of palindrome words.
TEACH
RACECAR
EXAM
MALAYALAM
Divyasha Satapathy 17
Program 14:
import java.util.Scanner;
class Program_14
System.out.println("Enter 5 words:");
String rev="";
int count=0;
for(int i=0;i<5;i++)
arr[i]=sc.next();
for(int j=0;j<5;j++)
for(int k=arr[j].length()-1;k>=0;k--)
rev=rev+arr[j].charAt(k);
Divyasha Satapathy 18
if(arr[j].equals(rev)==true)
count=count+1;
rev="";
Divyasha Satapathy 19
Variable Description Table:
Output:
Divyasha Satapathy 20
Question 15:
Bubble sort
Write a program in Java to input five city names in an array. Using bubble sort arrange
them in descending order and display the same.
Sample input: AGRA
MUMBAI
CHENNAI
DELHI
PUNE
Sample output:
PUNE
MUMBAI
DELHI
CHENNAI
AGRA
Divyasha Satapathy 21
Program 15:
import java.util.Scanner;
class Program_15
System.out.println("Enter 5 cities:");
for(int i=0;i<5;i++)
arr[i]=sc.next();
String temp="";
for(int k=0;k<4;k++)
if(arr[k].compareTo(arr[k+1])<0)
temp=arr[k];
arr[k]=arr[k+1];
Divyasha Satapathy 22
arr[k+1]=temp;
for(int l=0;l<5;l++)
System.out.println(arr[l]);
Divyasha Satapathy 23
Variable Description Table:
Output:
Divyasha Satapathy 24
Question 16:
Write a program to create two separate arrays A and B. Accept 6 numbers for each
array A and B. Find Sum1 and Sum2 as follows and print Sum1 and Sum2:
Divyasha Satapathy 25
import java.util.Scanner;
class Program_16
for(int i=0;i<6;i++)
array_A[i]=sc.nextDouble();
Divyasha Satapathy 26
}
for(int j=0;j<6;j++)
array_B[j]=sc.nextDouble();
double Sum1=0.0;
double Sum2=0.0;
for(int k=0,l=1;k<6&&l<6;k=k+2,l=l+2)
Sum1=Sum1+array_A[l]+array_B[k];
Sum2=Sum2+array_B[l]+array_A[k];
System.out.println("Sum1= "+Sum1);
System.out.println("Sum2= "+Sum2);
Divyasha Satapathy 27
Variable Description Table:
Divyasha Satapathy 28
the odd subscript in each array
Output:
Divyasha Satapathy 29
Question 17:
Linear Search - 1
Write a program to initialize an array of 10 names and initialize another array with their
respective telephone numbers. Using linear search technique, search for a name given
by the user in the list. If found, display “Search successful” and print the name along
with the telephone number, otherwise display “Search Unsuccessful. Name not
enlisted”.
Divyasha Satapathy 30
Program 17:
import java.util.Scanner;
class Program_17
System.out.println("Enter 10 names:");
boolean flag=false;
for(int i=0;i<10;i++)
name[i]=sc.next();
for(int j=0;j<10;j++)
Divyasha Satapathy 31
number[j]=sc.nextLong();
String search=sc.next();
for(int k=0;k<10;k++)
if(search.equals(name[k]))
System.out.println("Search successful");
System.out.println(name[k]);
System.out.println(number[k]);
flag=true;
break;
if(flag==false)
Divyasha Satapathy 32
Variable Description Table:
Output:
Divyasha Satapathy 33
Divyasha Satapathy 34
Question 18:
Linear Search - 2
Write a program to accept name and monthly salary of 5 employees and store them in
two separate arrays. Display the names of the employees who earn more than
Rs.50000 per month, using linear search.
Divyasha Satapathy 35
Program 18:
import java.util.Scanner;
class Program_18
for(int i=0;i<5;i++)
name[i]=sc.next();
Divyasha Satapathy 36
for(int j=0;j<5;j++)
salary[j]=sc.nextDouble();
for(int k=0;k<5;k++)
if(salary[k]>50000)
System.out.println(name[k]);
Divyasha Satapathy 37
Variable Description Table:
Divyasha Satapathy 38