Solution to Computer Application 2022 Question Paper
Question 1.
(i) b boolean
(ii) d toUpperCase(char)
(iii) b 5
(iv) c Float
(v) b Wrapper
(vi) a GoodDay
(vii) b N-1
(viii) a private
(ix) b 150.0
(x) c Luck
Question 2.
//Search an element using Binary Search Technique
import java.util.*;
class Question2
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a[]={2,5,7,10,15,20,29,30,46,50};
//Input the search element
System.out.println("Enter element to search :");
int n=sc.nextInt();
int l=0,u=a.length,mid;
while(l<=u)
{
mid=(l+u)/2;
if(a[mid]==n)
{
System.out.println("Element present at index number "+mid);
System.exit(0);
}
if(a[mid]<n)
l=mid+1;
if(a[mid]>n)
u=mid-1;
}
System.out.println("Element not present in the given array");
}
}
Question 3.
//Find the character with highest and lowest ASCII values
import java.util.*;
class Question3
{
public static void main()
{
Scanner sc=new Scanner(System.in);
char c[]=new char[10];
//Input
System.out.println("Enter 10 characters:");
for(int i=0;i<10;i++)
{
c[i]=sc.next().charAt(0);
}
int l=c.length,high=c[0],low=c[0];
for(int i=0;i<l;i++)
{
if(c[i]>high)
high=c[i];
if(c[i]<low)
low=c[i];
}
System.out.println("Character with highest ASCII value "+(char)high);
System.out.println("Character with lowest ASCII value "+(char)low);
}
}
Question 4.
//Find the square value of each element and product of all array elements
import java.util.*;
class Question4
{
public static void main()
{
Scanner sc=new Scanner(System.in);
double d[]=new double[10];
//Input
System.out.println("Enter 20 double type values:");
for(int i=0;i<10;i++)
{
d[i]=sc.nextDouble();
}
double pr=1.0;
int l=d.length;
for(int i=0;i<l;i++)
{
pr=pr*d[i];
System.out.println("Square of "+d[i]+"is " +(d[i]*d[i]));
}
System.out.println("Product of all elements "+pr);
}
}
Question 5.
//Change case of the letters of the String
import java.util.*;
class Question5
{
public static void main()
{
Scanner sc=new Scanner(System.in);
//Input
System.out.println("Enter String :");
String s=sc.nextLine();
int l=s.length();
char ch;
String ns="";
for(int i=0;i<l;i++)
{
ch=s.charAt(i);
if(Character.isUpperCase(ch))
ns=ns+Character.toLowerCase(ch);
else
if(Character.isLowerCase(ch))
ns=ns+Character.toUpperCase(ch);
else
ns=ns+ch;
}
System.out.println("Entered String :"+s );
System.out.println("String after changing case :"+ns);
}
}
Question 6.
//To check the first and last letters of the String
import java.util.*;
class Question6
{
public static void main()
{
Scanner sc=new Scanner(System.in);
//Input
String s[]=new String[10];
System.out.println("Enter 10 words :");
for(int i=0;i<10;i++)
{
s[i]=sc.next();
}
for(int i=0;i<10;i++)
{
if((s[i].startsWith("A")||s[i].startsWith("a")) && (s[i].endsWith("A") || s[i].endsWith("a")))
System.out.println(s[i] );
}
}
}
Question 7.
//To check the first and last letters of the String
import java.util.*;
class Question7
{
public static void main()
{
Scanner sc=new Scanner(System.in);
//Input
System.out.println("Enter two Strings of same length :");
String s1=sc.nextLine();
String s2=sc.nextLine();
String ns="";
int l1=s1.length();
int l2=s2.length();
if(l1!=l2)
{
System.out.println("Lengths are not same ");
System.exit(0);
}
for(int i=0;i<l1;i++)
{
ns=ns+s1.charAt(i)+s2.charAt(i);
}
System.out.println(ns);
}