Section A: ICSC 2022
Section A: ICSC 2022
Section A
Question 1(i)
1. Boolean
2. boolean
3. bool
4. char
Answer
boolean
Reason — isLetter() method returns true if the specified character is a letter else, it returns
false. Thus, the return data type of isLetter(char) is boolean.
Question 1(ii)
1. toUpper()
2. ToUpperCase()
3. toUppercase()
4. toUpperCase(char)
Answer
toUpperCase(char)
Question 1(iii)
1. 0
2. 5
3. 6
4. -5
Answer
Reason — indexOf() returns the index of the first occurrence of the specified character
within the string and lastIndexOf() returns the index of the last occurrence of the specified
character within the string. Since a string begins with index 0, the given methods are
evaluated as follows:
⇒0+6
"SUCESS".indexOf('S') + "SUCCESS".lastIndexOf('S')
⇒6
Question 1(iv)
1. FLOAT
2. float
3. Float
4. Floating
Answer
Float
Question 1(v)
............... class is used to convert a primitive data type to its corresponding object.
1. String
2. Wrapper
3. System
4. Math
Answer
Wrapper
Reason — Wrapper class is used to convert a primitive data type to its corresponding object.
Question 1(vi)
1. GoodDay
2. Good Day
3. Goodday
4. goodDay
Answer
GoodDay
Reason — concat() method is used to join two strings. Thus, "Good" and "Day" are joined
together and printed as "GoodDay".
Question 1(vii)
A single dimensional array contains N elements. What will be the last subscript?
1. N
2. N-1
3. N-2
4. N+1
Answer
N-1
Reason — The index of an array begins from 0 and continues till Size - 1. Thus, if an array
has N elements, the last subscript/index will be N - 1.
Question 1(viii)
1. private
2. public
3. protected
4. package
Answer
private
Reason — A data member or member method declared as private is only accessible inside
the class in which it is declared. Thus, it gives the least accessibility.
Question 1(ix)
1. 100
2. 150.0
3. 100.0
4. 150
Answer
150.0
Reason — parseDouble() method returns a double value represented by the specified string.
Thus, double values 56.0 and 94.0 are stored in C and D, respectively. Both C and D are
added and 150.0 (56.0 + 94.0) is printed on the screen.
Question 1(x)
1. Lucknow
2. Luckn
3. Luck
4. luck
Answer
Luck
Reason — The substring() method returns a substring beginning from the startindex and
extending to the character at index endIndex - 1. Since a string index begins at 0, the
character at startindex (0) is 'L' and the character at the endIndex (4-1 = 3) is 'k'. Thus, "Luck"
is extracted and printed on the screen.
Section B
Question 2
Define a class to perform binary search on a list of integers given below, to search for an
element input by the user, if it is found display the element along with its position, otherwise
display the message "Search element not found".
import java.util.Scanner;
if (index == -1) {
System.out.println("Search element not found");
}
else {
System.out.println(n + " found at position " +
index);
}
}
}
Output
Question 3
Define a class to declare a character array of size ten. Accept the characters into the array and
display the characters with highest and lowest ASCII (American Standard Code for
Information Interchange) value.
EXAMPLE :
INPUT:
'R', 'z', 'q', 'A', 'N', 'p', 'm', 'U', 'Q', 'F'
OUTPUT :
Character with highest ASCII value = z
Character with lowest ASCII value = A
import java.util.Scanner;
System.out.println("Enter 10 characters:");
for (int i = 0; i < len; i++)
{
ch[i] = in.nextLine().charAt(0);
}
char h = ch[0];
char l = ch[0];
if (ch[i] < l)
{
l = ch[i];
}
}
Output
Question 4
Define a class to declare an array of size twenty of double datatype, accept the elements into
the array and perform the following :
import java.util.Scanner;
System.out.println("Enter 20 numbers:");
for (int i = 0; i < l; i++)
{
arr[i] = in.nextDouble();
}
Output
Question 5
Define a class to accept a string, and print the characters with the uppercase and lowercase
reversed, but all the other characters should remain the same as before.
EXAMPLE:
INPUT : WelCoMe_2022
OUTPUT : wELcOmE_2022
import java.util.Scanner;
System.out.println(rev);
}
}
Output
Question 6
Define a class to declare an array to accept and store ten words. Display only those words
which begin with the letter 'A' or 'a' and also end with the letter 'A' or 'a'.
EXAMPLE :
Input : Hari, Anita, Akash, Amrita, Alina, Devi Rishab, John, Farha, AMITHA
Output: Anita
Amrita
Alina
AMITHA
import java.util.Scanner;
Output
Question 7
Define a class to accept two strings of same length and form a new word in such a way that,
the first character of the first word is followed by the first character of the second word and
so on.
Example :
Input string 1 – BALL
Input string 2 – WORD
OUTPUT : BWAOLRLD
import java.util.Scanner;
if(s2.length() == len)
{
for (int i = 0; i < len; i++)
{
char ch1 = s1.charAt(i);
char ch2 = s2.charAt(i);
str = str + ch1 + ch2;
}
System.out.println(str);
}
else
{
System.out.println("Strings should be of same
length");
}
}
}
Output