Sail E0 Webinar
Question


What is the output of this program?


class output {
public static void main(String args[])
{
String s1 = "Hello World";
String s2 = s1.substring(0 , 4);
System.out.println(s2);
}
}
Options:
A .  Hell
B .  Hello
C .  Worl
D .  World
Answer: Option A

substring(0,4) returns the character from 0 th position to 3 rd position.
output:
$ javac output.java
$ java output
Hell



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers