aliensbrain
  • Home
  • Study
  • Quizzes
  • 🎤AI Practicefree
  • Notebooks
  • Community
  • Sign in
  • Java Practice Test - 5
  • What will be the output of the program? String a = "newsp...
Multiple choice

What will be the output of the program? String a = "newspaper"; a = a.substring(5,7); char b = a.charAt(1); a = a + b; System.out.println(a);

  1. apa

  2. app

  3. apea

  4. apep

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Both substring() and charAt() methods are indexed with a zero-base, andsubstring() returns a String of length arg2 - arg1.

Keep practicing — related questions

  • class a { public staic void main(String ar[]) { String s="abcxyz"; s.substring(2,5) System.out.println(s); } }
  • class a { public staic void main(String ar[]) { String s="abcxyz"; s.substring(2,5); System.out.println(s);...
  • What will be the output of the below code snippet? public class Quiz2 { public static void main(String args...
  • What will be the output of the program? public class StringRef { public static void main(String [] args) { ...
  • What will be the output of the program? String x = "xyz"; x.toUpperCase(); /* Line 2 */ String y = x.replac...
  • What will be output from the following statements: System.out.println(1+2+"3"); System.out.println("1"+2+3);
  • What will be the output of the given code? String s = “Welcome To Java” s.substring(4, 4);
  • What will be the output of given code? String s = “Welcome To Java”; s.length(); s.charAt(9);
Play the full quiz 🎤 Practise this topic out loud
Advertisement
© Aliensbrain | all rights reserved
  • About
  • Contact
  • Terms and Condition
  • Privacy Policy