aliensbrain
  • Home
  • Study
  • Quizzes
  • 🎤AI Practicefree
  • Notebooks
  • Community
  • Sign in
  • Core Java (GATE - CS)
  • What is the output of the given Java program? public clas...
Multiple choice

What is the output of the given Java program?

public class MyClass
{
public static void main(String[] args)
{
String s = " Java Duke ";
int len = s.trim().length();
System.out.print(len);
}
}

  1. 8

  2. 9

  3. 11

  4. Compile time error

  5. Run time error

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

This is the correct choice. The program will print 9 as output. 

Keep practicing — related questions

  • What will be the output of the given program? class MyClass { public static void main(String AR[]) { short ...
  • What is the output of the given program? public class MyClass { public static void main(String[] args) { Sy...
  • What will be the result of compiling following code public class SampleClass { final int j ; public static ...
  • What is the output of following. public static void main(String[] args) { System.out.println("c="+args.leng...
  • What is the output of the given program? public class Example { public static void main(String[] args) { Sy...
  • What is the output of the following program?public class Demo { public static void main(String arg[]) { Sys...
  • What does it print? public class Elementary { public static void main(String[] args) { System.out.println(1...
  • What will be output of the following program? class A { static{ System.out.println("JAVA"); System.exit(0);...
Play the full quiz 🎤 Practise this topic out loud
Advertisement
© Aliensbrain | all rights reserved
  • About
  • Contact
  • Terms and Condition
  • Privacy Policy