ICSE Class 10 Computer Chapter 2 VSA Solutions: Java
ICSE Class 10 Computer Chapter 2 VSA Solutions
ICSE Class 10 Computer Chapter 2 Very Short Answer Questions test whether you can write exact Java statements, identify standard methods, trace loop output, and correct small syntax errors. The solutions below give the answer first, then explain the Java rule used, so you can check both the final answer and the reason behind it.
Concept snapshot: read a Java answer like a sentence
For a very short Java answer, read the statement from left to right like a precise instruction. The data type tells Java what kind of value will be stored, the method name tells Java what action to perform, the arguments inside parentheses are the inputs, and the semicolon ends the instruction. This helps you avoid common errors such as writing Math.pow without arguments or using an array name where one element is needed.
Java method reference for these questions
Most questions in this set are built from standard ICSE Computer Applications Java topics: the Math class, String methods, Character methods, arrays, type conversion, and loop tracing.
| Java item | Use in the question | Return value / note |
|---|---|---|
Math.pow(a, b) | Finds a raised to the power b | Returns a double |
Math.cbrt(c) | Finds the cube root of c | Returns a double |
Math.random() | Generates a random decimal value | Takes no argument |
String.valueOf(pno) | Converts a number to a string | Useful before searching digits as text |
s.indexOf("945") | Checks where a substring first occurs | Returns -1 if not found |
s.lastIndexOf('@') | Finds the last position of a character | Returns an int |
s.endsWith("KUMAR") | Tests whether a string ends with the given suffix | Returns true or false |
s.substring(start, end) | Extracts part of a string | Includes start, excludes end |
Character.isLetter(ch) | Checks whether one character is an alphabet | The argument must be a single char |
Character.isLetterOrDigit(ch) | Checks whether a character is a letter or digit | Returns true or false |
Chapter 2 Very Short Answer Questions solved
The answers below are written in a board-answer style: direct final answer, followed by a short explanation. Where a Java statement can be written with a variable name chosen by the student, the variable name used here is only a clear example.
Question 48: Write the Java statement for the sum of a raised to b and the cube root of c.
Answer:
double ans = Math.pow(a, b) + Math.cbrt(c);Working: The phrase “a raised to b” is written as Math.pow(a, b). The cube root of c is written as Math.cbrt(c). Since both methods return a double, the suitable variable type is double.
If the question asks only for the expression, the required expression is:
Math.pow(a, b) + Math.cbrt(c)Question 49: Name the following.
(a) Method with the same name as the class and invoked every time an object is created.
Answer: Constructor.
Reason: A constructor has the same name as its class and is called automatically when an object of that class is created.
(b) Keyword used to access the classes of a package.
Answer: import.
Reason: The import keyword allows a program to use classes from a package, such as java.util.Scanner.
Question 50: Name the following Java methods.
(a) A Character method that checks whether a character is an alphabet or a number.
Answer: Character.isLetterOrDigit(ch).
Reason: This method returns true when ch is either a letter or a digit.
(b) A Math method that does not have an argument.
Answer: Math.random().
Reason: Math.random() does not need an input argument. It returns a random double value in the range from 0.0 up to, but not including, 1.0.
Question 51: Fill in the blanks to print phone numbers containing 945.
void check(long pno)
{
String s = _______(a)_________;
if(______(b)_______)
System.out.println(pno);
}Answer:
void check(long pno)
{
String s = String.valueOf(pno);
if(s.indexOf("945") >= 0)
System.out.println(pno);
}Step 1: The phone number is stored as a long, but the question asks us to search for the digit pattern "945". A substring search is easier after converting the number to a String.
String s = String.valueOf(pno);Step 2: The method indexOf("945") returns the starting index of "945" if it is present. If the substring is absent, it returns -1.
Step 3: Therefore, the condition should check whether the returned index is not negative.
if(s.indexOf("945") >= 0)Final answer: Blank (a) is String.valueOf(pno); blank (b) is s.indexOf("945") >= 0.
Question 52: Fill in the blanks to count names ending with KUMAR.
void count(String s[])
{
int i, l=_________, c=0;
for(i=0;i<l;i++)
{
if(________________)
c++;
}
System.out.println(c);
}Answer:
void count(String s[])
{
int i, l = s.length, c = 0;
for(i = 0; i < l; i++)
{
if(s[i].endsWith("KUMAR"))
c++;
}
System.out.println(c);
}Working: The number of elements in the array is obtained by s.length. Each name is one element of the array, so the current name is s[i]. The method endsWith("KUMAR") checks whether that name ends with the exact suffix KUMAR.
Important note: endsWith() is case-sensitive. The string "Ravi Kumar" does not end with "KUMAR" unless it is converted or stored in uppercase.
Question 53: Extract PASS and PASSION from COMPASSION.
Answer:
String word = "COMPASSION";
System.out.println(word.substring(3, 7)); // PASS
System.out.println(word.substring(3)); // PASSIONWorking: Java string indexing starts from 0.
| Character | C | O | M | P | A | S | S | I | O | N |
|---|---|---|---|---|---|---|---|---|---|---|
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
For PASS, the substring starts at index 3 and must include the character at index 6. Since the ending index in substring(start, end) is excluded, we use 7 as the ending index.
For PASSION, the substring starts at index 3 and continues to the end, so substring(3) is enough.
Question 54: Give the output when a = 6 and b = 4.
for(k=a; k<=a*b; k+=a)
{
if(k%b==0)
break;
}
System.out.println(k);Answer:
12Step-by-step trace:
| Pass | Value of k | Condition k <= a*b | Check k % b == 0 | Result |
|---|---|---|---|---|
| Start | k = a = 6 | 6 <= 24, true | 6 % 4 = 2 | No break |
| Next | k = 12 | 12 <= 24, true | 12 % 4 = 0 | break executes |
When the loop breaks, k is 12. Therefore, System.out.println(k); prints 12.
Question 55: Correct the error in the character array program.
char arr[]={'4', '&', 'a', 'w', 'd'};
int i;
for(i=0;i<arr.length;i++)
{
if(Character.isLetter(arr))
System.out.println(arr);
}Corrected code:
char arr[] = {'4', '&', 'a', 'w', 'd'};
int i;
for(i = 0; i < arr.length; i++)
{
if(Character.isLetter(arr[i]))
System.out.println(arr[i]);
}Explanation: The method Character.isLetter() checks one character at a time. The name arr refers to the whole array, not one element. Inside the loop, the current character is arr[i], so both the condition and the print statement must use arr[i].
Output of the corrected program:
a
w
dQuestion 56: Name the type of type casting.
(a)
double m = 'b';Answer: Implicit type casting, also called widening conversion.
Reason: A char value can be converted automatically to a double. Java uses the character’s Unicode value in the conversion. The character 'b' has the value 98, so m receives 98.0.
(b)
char ch = (char)68;Answer: Explicit type casting, also called narrowing conversion.
Reason: The cast operator (char) tells Java to convert the integer value 68 into its corresponding character. In Unicode/ASCII for English uppercase letters, 68 represents 'D'.
Question 57: Write Java statements using suitable data types.
(a) Assign the cube root of -343 to a variable.
Answer:
double root = Math.cbrt(-343);Working: The method Math.cbrt() returns a double. The cube root of -343 is -7.0, because (-7) * (-7) * (-7) = -343.
(b) Assign the position of the last occurrence of @ in the string s.
Answer:
int pos = s.lastIndexOf('@');Working: A string index is an integer position. Therefore, the suitable data type is int. The method lastIndexOf('@') returns the last position of @, or -1 if it is absent.
Question 58: Mention the output of the code snippet.
int lives = 5;
System.out.println(lives--);
System.out.println(lives);Answer:
5
4Working: The expression lives-- uses the postfix decrement operator. In postfix form, Java first uses the current value and then decreases it by 1. Therefore, the first print statement prints 5. After that, lives becomes 4, so the second print statement prints 4.
Question 59: Convert the for loop to an exit-controlled loop.
for(k = 10; k >= -1; k--)
System.out.println(k*2);
System.out.println(k*4);Answer:
k = 10;
do
{
System.out.println(k * 2);
k--;
} while(k >= -1);
System.out.println(k * 4);Working: An exit-controlled loop checks its condition after running the loop body, so the correct form is do-while. The initialization k = 10 must come before the loop. The update k-- must be placed inside the loop body after the print statement.
Key point: In the original code, there are no braces after the for statement. Therefore, only System.out.println(k*2); belongs to the loop. The statement System.out.println(k*4); runs once after the loop finishes, so it must remain outside the do-while loop.
Question 60: Give the output of the array loop.
int x[]={2,45,7,67,12,3};
int i, t=0;
for(i=0, t=5; i<3; i++, t--)
{
System.out.println(x[i]+x[t]);
}Answer:
5
57
74Step-by-step trace:
| Iteration | i | t | Expression | Printed value |
|---|---|---|---|---|
| 1 | 0 | 5 | x[0] + x[5] = 2 + 3 | 5 |
| 2 | 1 | 4 | x[1] + x[4] = 45 + 12 | 57 |
| 3 | 2 | 3 | x[2] + x[3] = 7 + 67 | 74 |
After the third iteration, i becomes 3. The condition i < 3 becomes false, so the loop stops.
Quick answer index
Use this index only after reading the worked solution once. In ICSE Computer Applications, the working is often where the reason for the answer becomes clear.
| Question | Answer / final result |
|---|---|
| 48 | double ans = Math.pow(a, b) + Math.cbrt(c); |
| 49(a) | Constructor |
| 49(b) | import |
| 50(a) | Character.isLetterOrDigit(ch) |
| 50(b) | Math.random() |
| 51(a) | String.valueOf(pno) |
| 51(b) | s.indexOf("945") >= 0 |
| 52 | l = s.length and s[i].endsWith("KUMAR") |
| 53(a) | word.substring(3, 7) |
| 53(b) | word.substring(3) |
| 54 | 12 |
| 55 | Use arr[i] in Character.isLetter(arr[i]) and System.out.println(arr[i]) |
| 56(a) | Implicit type casting / widening conversion |
| 56(b) | Explicit type casting / narrowing conversion |
| 57(a) | double root = Math.cbrt(-343); |
| 57(b) | int pos = s.lastIndexOf('@'); |
| 58 | 5, then 4 |
| 59 | Use a do-while loop and keep System.out.println(k * 4); outside the loop |
| 60 | 5, 57, 74 |
Exam relevance for ICSE Computer Applications
The CISCE Computer Applications syllabus expects students to understand Java as an object-oriented language and to apply Java syntax in small code fragments as well as programs. These very short answer questions are useful because they check the exact skills needed before longer programming answers: method selection, data type selection, string indexing, loop tracing, and error correction.
Examiner’s mindset: where marks are usually lost
In short Java answers, an examiner looks for exact syntax and correct reasoning. A student may know the idea but lose credit by writing pow(a,b) instead of Math.pow(a, b), by forgetting that substring(3, 7) excludes index 7, or by tracing a postfix decrement as if it were prefix. For output questions, write the values line by line in the same order in which System.out.println() executes.
How to revise this chapter efficiently
- Make a one-page list of Java library methods:
Math,String, andCharacter. - Trace output questions in a table with columns for each changing variable.
- For string questions, write the index positions under each character before choosing
substring(). - For error-correction questions, check whether the method expects a single value, an array element, or an object.
Extra worked competency practice
The following teacher-made examples use the same Java skills as the solved set. They are included for practice and are not presented as extra textbook question numbers.
Worked example 1: Check whether an email contains @
Question: Write a Java condition to check whether the string email contains the character @.
Answer:
if(email.indexOf('@') != -1)Working: The method indexOf('@') returns the first position of @. If @ is absent, it returns -1. Therefore, != -1 means the character is present.
Worked example 2: Predict output with prefix decrement
Question: Give the output.
int n = 5;
System.out.println(--n);
System.out.println(n);Answer:
4
4Working: The operator --n is prefix decrement. Java first decreases n from 5 to 4, then prints it. The second print statement also prints the current value, which is 4.
Worked example 3: Extract a word using substring
Question: Write a Java statement to print CODE from "ENCODER".
Working:
| Character | E | N | C | O | D | E | R |
|---|---|---|---|---|---|---|---|
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
The word CODE starts at index 2 and ends at index 5. The ending index in substring(start, end) must be one more than the last required index.
Answer:
System.out.println("ENCODER".substring(2, 6));Common mistakes students make
- Writing
Math.powwithoutMath.: In standard school-level Java answers, writeMath.pow(a, b), not onlypow(a, b). - Forgetting that string positions start from zero: The first character of a Java string is at index
0, not index1. - Including the wrong ending index in
substring():substring(3, 7)includes index3to index6. It does not include index7. - Using the whole array instead of one element:
arrmeans the complete array, whilearr[i]means the current element. - Confusing postfix and prefix operators:
lives--prints first and then decreases;--livesdecreases first and then prints. - Moving statements into a loop without checking braces: If a loop has no braces, only the first statement after the loop header belongs to it.
Related ICSE Computer resources
Use these links to continue revision on the same site: ICSE Class 10 Computer Applications solutions, ICSE Class 10 solutions, ICSE solutions by class and subject, and ICSE syllabus resources.
Official source check
This page follows the Java topics listed for ICSE Computer Applications, including object-oriented programming concepts, identifiers, literals, data types, type conversions, Java methods, and basic programming logic. For official syllabus reference, students should use CISCE. For the exact behaviour of standard Java library methods such as String, Math, and Character, the relevant authority is the Oracle Java documentation.
Frequently Asked Questions
How should I write ICSE Class 10 Computer very short answers in Java?
Write the exact Java statement or term first, then add one brief reason if the question asks for explanation. For method-based answers, include the class name where needed, such as Math.cbrt(-343) or Character.isLetter(ch).
Why is substring(3, 7) used to print PASS from COMPASSION?
Java counts string indexes from 0, and substring(start, end) excludes the ending index. In COMPASSION, P is at index 3 and the second S is at index 6, so the ending index must be 7.
What is the difference between arr and arr[i] in ICSE Computer programs?
arr refers to the whole array, while arr[i] refers to one element of the array at index i. Methods such as Character.isLetter() need one character, so arr[i] is correct and arr is not.
How do I trace loop output questions correctly?
Make a small table and update every changing variable after each iteration. For example, in a loop with i++ and t--, write the values of both i and t before calculating the printed expression.
Is Math.random() a method without arguments?
Yes. Math.random() takes no argument and returns a double value from 0.0 up to, but not including, 1.0. The empty parentheses are still required because it is a method call.