ICSE · Class 10 · Computer Applications
Class 10 String Handling Mock Test (ICSE)
5 practice questions from String Handling, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.
Topics in String Handling
- String class methods: length, charAt, indexOf, substring
- compareTo, equals and equalsIgnoreCase
- toUpperCase, toLowerCase, trim, replace
- String concatenation
- Programs on words, palindromes and character frequency
String Handling practice questions with answers
- Q1Multiple choice1 markWhat is the output of the expression given below? " ICSE Java ".trim().length();
- (a)13
- (b)11
- (c)10
- (d)9
Show answer and step marks
- Correct option: (d) 9+1
Answer: (d) - Q2Multiple choice1 markWhat will be the output of the following statement? System.out.println(10 + 20 + "Java" + 10 + 20);
- (a)1020Java30
- (b)30Java1020
- (c)30Java30
- (d)1020Java1020
Show answer and step marks
- Correct option: (b) 30Java1020+1
Answer: (b) - Q3Multiple choice1 markWhat will be the output of the following statement? System.out.println("Computer".compareTo("Computers"));
- (a)8
- (b)-1
- (c)1
- (d)0
Show answer and step marks
- Correct option: (b) -1+1
Answer: (b) - Q4Multiple choice1 markWhich of the following expressions correctly checks if a string variable str contains the character 'a' or 'A'?
- (a)str.contains('a')
- (b)str.search('a')
- (c)str.indexOf('a') ≥ 0 || str.indexOf('A') ≥ 0
- (d)str.indexOf("a", "A") ≠ -1
Show answer and step marks
- Correct option: (c) str.indexOf('a') ≥ 0 || str.indexOf('A') ≥ 0+1
Answer: (c) - Q5Long answer4 marksWrite a program in Java to accept a sentence from the user. Convert the sentence to uppercase. Count and display the frequency of each vowel (, , , , ) present in the sentence using string handling methods.
Show answer and step marks
- Importing Scanner class, creating the class and main method, and accepting the sentence.+1
- Converting the string to uppercase and setting up variables/counters for each vowel.+1
- Using a loop with charAt() and conditional statements to correctly count the frequency of each vowel.+1
- Displaying the frequency of each vowel with proper output messages.+1
Answer: import java.util.Scanner; class Vowels { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine().toUpperCase(); int a = 0, e = 0, i = 0, o = 0, u = 0; for (int k = 0; k < s.length(); k++) { char c = s.charAt(k); if (c == 'A') a++; else if (c == 'E') e++; else if (c == 'I') i++; else if (c == 'O') o++; else if (c == 'U') u++; } System.out.println("A = " + a + ", E = " + e + ", I = " + i + ", O = " + o + ", U = " + u); } }
Take a full String Handling test
PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.
- 15 min10 marks
- 30 min20 marks
- 1.5 hr40 marks
- 3 hr80 marks
Get your String Handling answers marked
Sign in, pick this chapter and a length, write the test on paper and get every step marked.
Sign in to take this test