Character class methods are found in the package called:
- java.util
- java.lang
- java.awt
- java.io
Answer
java.lang
Reason — The Character class methods are found in the java.lang package because this package contains fundamental classes that are automatically available in every Java program. The Character class provides methods to work with characters, such as checking whether a character is a letter, digit, uppercase, or lowercase.
System.out.println('Z' + 32); will display:
- z
- Z
- 122
- 154
Answer
122
Reason — In the statement System.out.println('Z' + 32);, the character 'Z' is converted to its ASCII value 90, and then 32 is added to it, giving the result 122. Since the + operator with a character and an integer results in an integer, the output displayed will be 122.
double x[] = {2.5, 4.5, 5.5, 6.4}; occupies ............... bytes.
- 16
- 4
- 8
- 32
Answer
32
Reason — The double data type in Java occupies 8 bytes of memory. In the array double x[] = {2.5, 4.5, 5.5, 6.4};, there are 4 elements, and each element takes 8 bytes. So, the total memory occupied is 4 × 8 = 32 bytes.
The output of 42 / 6 % 2 is:
- 1
- 10
- 2
- 0
Answer
1
Reason — According to operator precedence in Java, division (/) and modulus (%) have the same priority and are evaluated from left to right.
42 / 6 % 2
= 7 % 2
= 1
Consider the two-dimensional array P[2][3], of peripherals (input/output devices) given below, state the index of the device Barcode Scanner.
![Consider the two-dimensional array P[2][3], of peripherals (input/output devices) given below, state the index of the device Barcode Scanner. ICSE 2025 Computer Applications Solved Question Paper.](https://cdn1.knowledgeboat.com/img/abp10/1/q1-5-icse-computer-board-2025-year-1134x730.png)
- P[1][1]
- P[0][1]
- P[1][2]
- P[0][0]
Answer
P[1][1]
Reason — In a two-dimensional array P[2][3], the first index represents the row and the second index represents the column. The device "barcode scanner" is located in the second row (index 1) and the second column (index 1), so its index is P[1][1].
Which of the following is user-defined data type?

- only 1
- 1 and 3
- only 2
- only 4
Answer
1 and 3
Reason — A user-defined data type is a data type defined by the user. In the given options, array and class are user-defined data types because they are created by the user to store multiple values or define their own structure. double and boolean are predefined (primitive) data types.
Select the infinite loop:
- for(int i = 1; i <= 10; i++)
- for(int i = 2; i != 0; i -= 3)
- for(int i = 5; i <= 5; i++)
- for(int i = 1; i >= 1; i--)
Answer
for(int i = 2; i != 0; i -= 3)
Reason — The loop for(int i = 2; i != 0; i -= 3) is an infinite loop because the value of i starts at 2 and decreases by 3 in every iteration. Since i will never become 0 (it will take values like 2, -1, -4, -7, etc.), the condition i != 0 will always be true. Therefore, the loop will continue to run forever.
The output of Math.max(-7, Math.min(-5, -4)) is:
- -5
- -4
- -7
- error
Answer
-5
Reason — The method Math.min(-5, -4) returns the smaller of the two values, which is -5. Then, Math.max(-7, -5) returns the greater of the two values, which is -5. Hence, the final output of Math.max(-7, Math.min(-5, -4)) is -5.
Which of the following is true for the given object creation statement?
Game cricket = new Game();
- Game is an object of cricket class
- New keyword creates object Game
- Game is a class and cricket is an object
- Game and cricket are objects
Answer
Game is a class and cricket is an object
Reason — In the statement Game cricket = new Game();, Game is the name of the class, and cricket is the object (or instance) created from that class. The new keyword is used to create a new object of the class. Therefore, Game is the class, and cricket is the object.
Post Office is an example for ............... access specifier.
- public
- local
- protected
- private
Answer
public
Reason — A Post Office is accessible to everyone in a community, just like a public access specifier in programming, which allows members of a class to be accessible from any other class or part of the program. Hence, a Post Office is an example of public access specifier.
Assertion (A): In switch case, break statement avoids fall through.
Reason (R): break statement helps to execute only one case at a time.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Answer
Both (A) and (R) are true and (R) is a correct explanation of (A).
Reason — In a switch case, the break statement stops the program from executing the next cases after a match is found. Without the break, the program would continue to run all the cases below the matched one (called fall through). Therefore, the break statement helps to execute only one case at a time.
A physical education teacher asks the students to do the side stretch as shown below, 10 times. Which programming construct the teacher uses?

- if
- switch
- for
- if else if
Answer
for
Reason — The teacher asks the students to do the side stretch 10 times, which means repeating the same action multiple times. In programming, the for loop is used to repeat a block of code a specific number of times. Hence, the teacher is using the concept similar to a for loop to instruct repetition.
The index(subscript) of the last element of an array ar[] is:
- ar.length()
- ar[].length
- ar.length() – 1
- ar.length – 1
Answer
ar.length – 1
Reason — In Java, the length of an array ar is given by ar.length (without parentheses). Since array indexing starts from 0, the last element's index is always one less than the total length of the array. Therefore, the index of the last element is ar.length – 1.
Assertion (A): A clock is a real-life example of nested loops.
Reason (R): The hour hand moves through 12 positions, while the minute hand moves through 60 positions within each hour.
- Both (A) and (R) are true and (R) is a correct explanation of (A).
- Both (A) and (R) are true and (R) is not a correct explanation of (A).
- (A) is true and (R) is false.
- (A) is false and (R) is true.
Answer
Both (A) and (R) are true and (R) is a correct explanation of (A).
Reason — A clock is a real-life example of nested loops because the hour hand moves through 12 positions, and within each hour, the minute hand moves through 60 positions. This shows that one loop (minute hand) runs inside another loop (hour hand), which is similar to the concept of nested loops in programming.
Which of the following pairs of methods will cause a compile-time error due to incorrect method overloading?
- void test(int a, int b) and void test(double a, double b)
- void test(int a, double b) and void test(double a, int b)
- void test(int a, double b) and void test(int a)
- void test(int a) and int test(int a)
Answer
void test(int a) and int test(int a)
Reason — In Java, method overloading depends on the method's name and its parameter list (number or type of parameters). The return type alone is not considered for method overloading. So, void test(int a) and int test(int a) have the same name and same parameter list, which causes a compile-time error because they differ only in return type, not in parameters.
Which of the following converts "25" to 25.0?
- Double.Parsedouble("25")
- Double.parse("25")
- Double.parseDouble("25")
- Double.parseDouble(25)
Answer
Double.parseDouble("25")
Reason — In Java, the method Double.parseDouble("25") is used to convert a string containing a numeric value into a double data type. It belongs to the Double class and takes a string as an argument, returning its equivalent double value.
Consider the program segment:
int p = 0;
for(p = 4; p > 0; p -= 2);
System.out.print(p);
System.out.println(p);The above statement will display:
- 42
- 4200
- 0
0 - 00
Answer
00
Reason
1. Initialization: int p = 0;
- This line declares an integer variable
pand initializes it to 0.
2. For Loop: for(p = 4; p > 0; p -= 2);
p = 4→ loop starts withpassigned the value 4.- Condition:
p > 0is true (since 4 > 0). - The semicolon (
;) at the end means the loop body is empty and does nothing. - Update:
p -= 2decreasespby 2. - Next value of
p= 2 → still > 0, so the loop continues. - Decrease again:
p -= 2→p = 0→ now the conditionp > 0is false, loop stops.
3. After the Loop: p is now 0.
4. Output Statements:
System.out.print(p);prints 0 without moving to the next line.System.out.println(p);prints 0 and moves to the next line.
The output of the below statement is:
System.out.println("I said, \"It\'s wise to obey elders.\"");
- I said, 'It is wise to obey elders.'
- I said, "It's wise to obey elders."
- I said, It's wise to elders.
- "'It's wise to obey elders.'"
Answer
I said, "It's wise to obey elders."
Reason — In Java, the backslash \ is used as an escape character. The statement uses escape sequences:
\"to include double quotes inside a string.\'to include a single quote inside a string.
So the output preserves both the double quotes around "It's wise to obey elders." and the apostrophe in It's.
Hence, the output is: I said, "It's wise to obey elders."
What is the output of the statement given below?
"ANGER".compareTo("ANGEL")
- 3
- -6
- 6
- 0
Answer
6
Reason — The compareTo() method compares two strings lexicographically by comparing their characters one by one. It returns the difference between the first pair of characters that differ in the two strings.
Here, comparing "ANGER" and "ANGEL":
- Characters
'A','N','G', and'E'are the same in both strings at positions 0 to 3. - At position 4,
'R'(ASCII value 82) in"ANGER"is compared with'L'(ASCII value 76) in"ANGEL". - The difference is
82 - 76 = 6.
Thus, the output is 6.
Consider the following program segment in which the statements are jumbled.
Choose the correct order of statements to calculate and return the factorial of 4.
for(k = 1; k <= 4; k++) → 1
return fa; → 2
long fa = 1, k; → 3
fa *= k; → 4- 1, 2, 3, 4
- 3, 1, 4, 2
- 3, 1, 2, 4
- 1, 3, 2, 4
Answer
3, 1, 4, 2
Reason — To calculate and return the factorial of 4 using a loop, we must follow the proper sequence of statements:
long fa = 1, k;– This is the declaration and initialization of variablesfaandk.for(k = 1; k <= 4; k++)– This sets up a loop to run from 1 to 4.fa *= k;– This multiplies the current value offabykduring each iteration.return fa;– This returns the final calculated factorial value.
So, the correct order is: 3, 1, 4, 2, which correctly calculates and returns the factorial.
Write the Java expression to find the product of square root of P and the square root of Q using the methods of Math class.
Answer
Math.sqrt(P) * Math.sqrt(Q)
Write the output of the following String method:
String x = "talent";
String y = "matrix";
System.out.println(x.substring(3).concat(y.substring(3)));Answer
entrix
x.substring(3)returns the substring of"talent"from index 3 onwards, i.e.,"ent".y.substring(3)returns the substring of"matrix"from index 3 onwards, i.e.,"rix".- The
concat()method joins both substrings:"ent"+"rix"="entrix".
Write the Java statement for creating an object named 'sifra' of the class 'Robot', which takes three double parameters.
Answer
Robot sifra = new Robot(2.5, 3.5, 4.5);
Convert the given loop into exit-controlled loop.
int a, b;
for(a = 10, b = 1; a >= 1; a -= 2){
b += a;
b++;
}
System.out.print(b);Answer
int a = 10, b = 1;
do {
b += a;
b++;
a -= 2;
} while(a >= 1);
System.out.print(b);Consider and give the output of the following program:
class report{
int a, b;
report(){
a = 10;
b = 15;
}
report(int x, int y){
a = x;
b = y;
}
void print(){
System.out.println(a * b);
}
static void main(){
report r = new report();
r.print();
report p = new report(4, 5);
p.print();
}
}Answer
150
20
1. Class Definition:
- The class
reportis defined with two integer variables:aandb.
2. Constructors:
Default constructor:
report()
This constructor sets the values ofaandbto 10 and 15, respectively, when an object is created without any parameters.Parameterized constructor:
report(int x, int y)
This constructor accepts two integer valuesxandyand assigns them toaandb.
3. Method print():
- This method prints the product of the two variables
aandb.
4. Static method main():
Inside the main() method:
- First, an object
rof classreportis created using the default constructor. - Then, the
print()method is called onrwhich prints the product 10 * 15 = 150. - Next, an object
pis created using the parameterized constructor with values 4 and 5. - The
print()method is called onpwhich prints the product 4 * 5 = 20.
(a) Name one String method which results in positive integer only.
(b) Name one String method which results in a character.
Answer
(a) length()
(b) charAt()
John was asked to write a Java code to calculate the surface area of a cone. The following code was written by him: Surface area of cone is A = πrl
l =
class area{
double area(double r, double h){
double l, a;
a = 22.0 / 7 * r * l;
l = Math.sqrt(r * r + h * h);
return a;
}
}Specify the type of the error in the above program, correct and write the program to be error free.
Answer
The compile-time error occurs because the variable l is used before it is initialized.
The corrected code is as follows:
class area{
double area(double r, double h){
double l, a;
l = Math.sqrt(r * r + h * h);
a = 22.0 / 7 * r * l;
return a;
}
}Consider the following array and answer the questions given below:
int a[] = {12, 10, 8, 4, 6, 2, 3, 5, 7};
(a) What is the output of System.out.print(a[0] + a[5]);?
(b) What is the index (subscript) of the largest element of the array a[]?
Answer
(a) 14
(b) The largest element in the array is 12, which is at index 0.
- a[0] is 12.
- a[5] is 2.
- Sum = 12 + 2 = 14.
(a) Write the Java statement to initialize the first 6 odd numbers in a 3 × 2 array.
(b) What is the result of x[0][1] + x[2][1] of the above array?
Answer
(a) x[3][2] = {{1, 3}, {5, 7}, {9, 11}};
(b) 14
- x[0][1] = 3.
- x[2][1] = 11.
- Sum = 3 + 11 = 14.
Give the output of the following program segment and specify how many times the loop is executed.
String s = "JAVA";
for(i = 0; i < s.length(); i += 2)
System.out.println(s.substring(i));Answer
JAVA
VA
The loop executes 2 times.
- The string
xcontains the value"JAVA", which has a length of 4. - The
forloop initializesito 0 and increments it by 2 in each iteration (i = 0, 2). - In the first iteration, when
iis 0,x.substring(0)extracts the substring from index 0 to the end, which is"JAVA". This is printed. - In the second iteration, when
iis 2,x.substring(2)extracts the substring from index 2 to the end, which is"VA". This is printed. - When
ibecomes 4, the conditioni < x.length()(i.e.,4 < 4) becomes false, so the loop terminates. - Therefore, the loop executes exactly 2 times, printing the substrings
"JAVA"and"VA".
Define a class named CloudStorage with the following specifications:
Member Variables:
int acno – stores the user’s account number
int space – stores the amount of storage space in GB purchased by the user
double bill – stores the total price to be paid by the user
Member Methods:
void accept() – prompts the user to input their account number and storage space using Scanner class methods only.
void calculate() – calculates the bill total price based on the storage space purchased using the pricing table provided:
| Storage range | Price per GB (Rs) |
|---|---|
| First 15 GB | 15 |
| Next 15 GB | 13 |
| Above 30 GB | 11 |
void display() – displays the account number, storage space and bill to be paid.
Write a main method to create an object of the class and invoke the methods of the class with respect to the object.
import java.util.Scanner;
class CloudStorage{
int acno;
int space;
double bill;
public void accept(){
Scanner in = new Scanner(System.in);
System.out.print("Account number: ");
acno = in.nextInt();
System.out.print("Space: ");
space = in.nextInt();
}
public void calculate(){
if(space <= 15)
bill = space * 15;
else if(space <= 30)
bill = 225 + (space - 15) * 13;
else
bill = 420 + (space - 30) * 11;
}
public void display(){
System.out.println("Account No. " + acno);
System.out.println("Storage space: " + space);
System.out.println("Bill: " + bill);
}
public static void main(String[] args){
CloudStorage obj = new CloudStorage();
obj.accept();
obj.calculate();
obj.display();
}
}


Define a class to accept values into a 4 × 4 integer array. Calculate and print the NORM of the array.
NORM is the square root of sum of squares of all elements.
1 2 1 3
5 2 1 6
3 6 1 2
3 4 6 3
Sum of squares of elements = 1 + 4 + 1 + 9 + 25 + 4 + 1 + 36 + 9 + 36 + 1 + 4 + 9 + 16 + 36 + 9 = 201
NORM = Square root of 201 = 14.177446878757825
import java.util.Scanner;
class Norm{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int a[][] = new int[4][4];
int sum = 0;
System.out.println("Enter array elements:");
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
a[i][j] = in.nextInt();
}
}
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
sum += a[i][j] * a[i][j];
}
}
double root = Math.sqrt(sum);
System.out.println("NORM = " + root);
}
}
Define a class to accept a String and print if it is a Super String or not. A String is Super if the number of uppercase letters are equal to the number of lowercase letters. [Use Character and String methods only]
Example: “COmmITmeNt”
Number of uppercase letters = 5
Number of lowercase letters = 5
String is a Super String
import java.util.Scanner;
class SuperString{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
String s = in.nextLine();
int upper = 0;
int lower = 0;
int l = s.length();
for(int i = 0; i < l; i++){
char ch = s.charAt(i);
if(Character.isUpperCase(ch))
upper++;
else if(Character.isLowerCase(ch))
lower++;
}
if(upper == lower)
System.out.println("String is a Super String");
else
System.out.println("String is not a Super String");
}
}
Define a class to initialize the following data in an array.
Search for a given character input by the user, using the Binary Search technique.
Print “Search successful” if the character is found otherwise print “Search is not successful”.
‘A’, ‘H’, ‘N’, ‘P’, ‘S’, ‘U’, ‘W’, ‘Y’, ‘Z’, ‘b’, ‘d’
import java.util.Scanner;
class Search{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
char a[] = {'A', 'H', 'N', 'P', 'S', 'U', 'W', 'Y', 'Z', 'b', 'd'};
System.out.print("Character to be searched: ");
char key = in.next().charAt(0);
int low = 0;
int high = a.length - 1;
int mid = 0;
while(low <= high){
mid = (low + high) / 2;
if(key == a[mid])
break;
else if(key < a[mid])
high = mid - 1;
else
low = mid + 1;
}
if(low > high)
System.out.println("Search is not successful");
else
System.out.println("Search is successful");
}
}

Define a class to overload the method print() as follows:
void print() – To print the given format using nested loops.
@#@#@
@#@#@
@#@#@
@#@#@
double print(double a, double b) – To display the sum of numbers between a and b with difference of 0.5.
e.g. if a = 1.0, b = 4.0
Output is: 1.0 + 1.5 + 2.0 + 2.5 + … + 4.0
int print(char ch1, char ch2) – Compare the two characters and return the ASCII code of the largest character.
import java.util.Scanner;
class Overload {
public void print() {
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 5; j++) {
if (j % 2 == 0) {
System.out.print('@');
}
else {
System.out.print('#');
}
}
System.out.println();
}
}
public double print(double a, double b) {
double sum = 0.0;
for(double i = a; i <= b; i += 0.5)
sum += i;
System.out.println("Sum = " + sum);
return sum;
}
public int print(char ch1, char ch2) {
int maxAscii = (ch1 > ch2) ? (int)ch1 : (int)ch2;
System.out.println("Larger ASCII code = " + maxAscii);
return maxAscii;
}
public static void main(String[] args) {
Overload obj = new Overload();
Scanner sc = new Scanner(System.in);
System.out.println("Pattern:");
obj.print();
System.out.print("\nEnter two decimal values (a and b): ");
double a = sc.nextDouble();
double b = sc.nextDouble();
obj.print(a, b);
System.out.print("\nEnter two characters: ");
char ch1 = sc.next().charAt(0);
char ch2 = sc.next().charAt(0);
obj.print(ch1, ch2);
}
}
Define a class to accept a number. Check if the sum of the largest digit and the smallest digit is an even number or an odd number. Print appropriate messages.
| Sample Input: | 6425 | 3748 |
| Largest digit: | 6 | 8 |
| Smallest digit: | 2 | 3 |
| Sample Output: | Sum is even | Sum is odd |
import java.util.Scanner;
class Find{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = in.nextInt();
int sum = 0;
int s = 10;
int l = -1;
while (num != 0) {
int d = num % 10;
if (d < s)
s = d;
if (d > l)
l = d;
num /= 10;
}
sum = s + l;
if(sum % 2 == 0)
System.out.println("Sum is even");
else
System.out.println("Sum is odd");
}
}
