ICSE Comp App Set-2 2022

SECTION A

(Attempt all questions.)

Question 1

Choose the correct answers to the questions from the given options. (Do not copy the
the question, Write the correct answer only.)

i. When primitive data type is converted to its corresponding object of its class, it is
called as ___________. 

Answer: Boxing

ii. State the value of y after the following is executed:
char x=’7′;
y= Character.isLetter(x);

Answer: False

iii. Give the output of the following string methods:
“MISSISSIPPI”.indexOf(‘S’)+ “MISSISSIPPI”.lastIndexOf(‘I’)

Answer: 12

iv. Corresponding wrapper class of int data type is __________.

Answer: Integer

v. Variable that is declared with in the body of a method is termed as:

Answer: Local Variable

vi. Identify the correct array declaration statement:

Answer: int a[]=new int[10];

vii.A variable that is bounded to the object itself is called as:

Answer: Instance variable

viii. A variable that is bounded to the object itself is called as:

Answer: Public

ix. Give the output of the following code:
String A =”26.0″, B=”74.0″;
double C= Double .parseDouble(A);
double D = Double .parseDouble(B);
System.out.println((C+D));

Answer: 100.0

x. Wrapper classes are available in __________ package.

Answer: java.lang

SECTION B

(Attempt any four questions.)

Question 2: Define a class to declare an integer array of size n and accept the elements into the array. Search for an element input by the user using a linear search technique, and display the element if it is found, otherwise display the message “NO SUCH ELEMENT.

Answer:

import java.util.*;
public class integer
{
public static void main(String args[])
{
    Scanner in = new Scanner(System.in);
    int i,n,f,se;
    f=0;
    System.out.println("Enter The Number Of Terms");
    n=in.nextInt();
    int a[] = new int[n];
    System.out.println("Enter The Number In Array");
    for(i=0;i<n;i++)
    {
        System.out.println("Enter The Number At " +(i+1)+ " Position");
        a[i]=in.nextInt();
    }
    System.out.println("Enter The Element To Search");
    se=in.nextInt();
    
    for(i=0;i<n;i++)
    {
        if(a[i]==se)
        {
            f=1;
            break;
        }
    }
    if(f==1)
    System.out.println("Number Is Found At " +(i+1)+" Position");
    else
    System.out.println("No Such Element");
    }
}

Output:

Enter The Number Of Terms
5
Enter The Number In Array
Enter The Number At 1 Position
12
Enter The Number At 2 Position
25
Enter The Number At 3 Position
36
Enter The Number At 4 Position
95
Enter The Number At 5 Position
54
Enter The Element To Search
36
Number Is Found At 3 Position

Question 3: Define a class to declare a character array of size ten, accept the character into the array and perform the following:
• Count the number of uppercase letters in the array and print.
• Count the number of vowels in the array and print.

Answer:

import java.util.*;   
public class character  
{   
public static void main(String[] args)   
{
String st;
st="";
int i,l,c,vc;    
char ch;
c=0;
vc=0;
Scanner in=new Scanner(System.in); 
System.out.println("Enter the String"); 
st=in.nextLine();
l=st.length();
for(i=0;i< l;i++)    
{ 
ch=st.charAt(i); 
if(ch>='A' && ch<='Z')
  c++;     
if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'||ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')       
  vc++;
}    
System.out.println("No Of Upper Case Character = " +c);
System.out.println("No Of Vowel = " +vc);

}  
}

Output:

Enter the String
BeeOwn.com
No Of Upper Case Character = 2
No Of Vowel = 4

Question 4: Define a class to declare an array of size 20 of a double datatype, accept the elements into the array and perform the following:
• Calculate and print the sum of all the elements.
• Calculate and print the highest value of the array.

Answer:

import java.util.*;
public class Main
{
public static void main(String args[])
{
    Scanner in = new Scanner(System.in);
    int i,n;
    double s,h;
    System.out.println("Enter The Number Of Terms");
    n=in.nextInt();
    double a[] = new double[n];
    System.out.println("Enter The Number In Array");
    for(i=0;i<n;i++)
    {
        System.out.println("Enter The Number At " +(i+1)+ " Position");
        a[i]=in.nextDouble();
    }
    h=a[0];
    s=a[0];
    for(i=1;i<n;i++)
    {
        s=s+a[i];
        
        if(a[i]>h)
        h=a[i];
    }
    System.out.println("Sum Of All Elements In Array = " +s);
    System.out.println("Highest Elements In Array = "+h);
    }
}

Output:

Enter The Number Of Terms
5
Enter The Number In Array
Enter The Number At 1 Position
25.26
Enter The Number At 2 Position
58.45
Enter The Number At 3 Position
12.3
Enter The Number At 4 Position
86.99
Enter The Number At 5 Position
86.999
Sum Of All Elements In Array = 269.999
Highest Elements In Array = 86.999

Question 5: Define a class to accept two strings, convert them into uppercase, check and display whether two strings are equal or not, if the two strings are not equal, print the string with the highest length or print the message both the strings are of equal length.

Answer:

import java.util.*;   
public class Main  
{   
public static void main(String[] args)   
{
String st,st1;
int l,l1;    
Scanner in=new Scanner(System.in); 
System.out.println("Enter The First String"); 
st=in.nextLine();
System.out.println("Enter The Secound String"); 
st1=in.nextLine();

st=st.toUpperCase();
st1=st1.toUpperCase();

if(st.equals(st1))
System.out.println("Both The String Are Equal");
else
{
    l=st.length();
    l1=st1.length();
    if(l>l1)
    {
       System.out.println("Length Of Highest String = " +l); 
       System.out.println("Highest String = " +st); 
    }
    else if(l1>l)
    {
       System.out.println("Length Of Highest String = " +l1); 
       System.out.println("Highest String = " +st1); 
    }
    else
    System.out.println("Both String Have Same Length ");
    
}
}  
}

Output:

Enter The First String
BeeOwn
Enter The Secound String
beeown
Both The String Are Equal


Enter The First String
beeown.com
Enter The Secound String
BeeOwn
Length Of Highest String = 10
Highest String = BEEOWN.COM

Question 6: Define a class to accept a string, convert it into lowercase, and check whether the string is a palindrome or not.
A palindrome is a word that reads the same backward as forward.
Example:
madam, racecar, etc.

Answer:

import java.util.*;   
public class Main  
{   
public static void main(String[] args)   
{
String st,st1,st2;
int i,l,l1;
char ch;
Scanner in=new Scanner(System.in); 
System.out.println("Enter The String"); 
st=in.nextLine();
st=st.toLowerCase();
l=st.length();

st1="";
st2="";
for(i=0;i<l;i++)
{
    ch=st.charAt(i);
    st1=st1+ch;
    st2=ch+st2;
}
if(st1.equals(st2))
System.out.println("Palindrome Word = "+st);
else
System.out.println("Not Palindrome Word = "+st);
}  
}

Output:

Enter The String
Madam
Palindrome Word = madam

Enter The String
BeeOwn
Not Palindrome Word = beeown

Question 7

Define a class to accept and store 10 strings into the array and print the strings with even
a number of characters.

Answer:

import java.util.*;   
public class Main  
{   
public static void main(String[] args)   
{
    int i,l,n;
    Scanner in=new Scanner(System.in); 
    System.out.println("Enter The Number Of Terms");
    n=in.nextInt();
    String st[] = new String[n];
    System.out.println("Enter The String In Array");
    for(i=0;i<n;i++)
    {
        System.out.print("Enter The String At " +(i+1)+ " Position ");
        st[i]=in.next();
        
    }
    System.out.println("Even Number Of String Are");
    for(i=0;i<n;i++)
    {
        l=st[i].length();
        if(l%2==0)
        System.out.println(st[i]);
    }
}
}

Output:

Enter The Number Of Terms
5
Enter The String In Array
Enter The String At 1 Position BeeOwn
Enter The String At 2 Position Website
Enter The String At 3 Position WebPage
Enter The String At 4 Position Newrton
Enter The String At 5 Position Madam
Even Number Of String Are
BeeOwn
Newton

You may also like SET1

Share your love