KnowledgeBoat Logo

Output Questions for Class 10 ICSE Computer Applications

Consider the below function:

void strop(String s) {
    char a = s.charAt(3);
    int b = s.indexOf('M');
    String t = s.substring(3,6);
    boolean p = s.equals(t);
    System.out.println(a + " " + b + " " + t + " " + p);
}

What will be the output for strop("COMPUTER")?

Java

Java String Handling

10 Likes

Answer

P 2 PUT false

Working

  1. s.charAt(3) returns the letter at index 3 of s which is P. This gets assigned to variable a.
  2. Index of letter M in s is 2.
  3. s.substring(3,6) returns a substring of s starting at index 3 till index 5. So PUT gets assigned to t.
  4. As PUT is not equal to the value of s (which is COMPUTER) so p becomes false.

Answered By

5 Likes