Strings - Study Mode

[#86] Determine output: public class Test{
public static void main(String args[]){
String str = null
if(str.length() == 0){
System.out.print("1")
}
else if(str == null){
System.out.print("2")
}
else{
System.out.print("3")
}
}
}
Correct Answer

Compilation fails.

[#87] What will be the output of the following Java program? class output
{
public static void main(String args[])
{
String s1 = "Hello World"
String s2 = s1.substring(0 , 4)
System.out.println(s2)
}
}
Correct Answer

(A) Hell

[#88] What will be the output of the following Java code? class output
{
public static void main(String args[])
{
char ch
ch = "hello".charAt(1)
System.out.println(ch)
}
}
Correct Answer

(B) e

[#89] What will be the output of the following Java program? class String_demo
{
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68}
String s = new String(ascii, 1, 3)
System.out.println(s)
}
}
Correct Answer

(B) BCD

[#90] What will be the output of the following Java program? class output
{
public static void main(String args[])
{ String s = "Hello World"
int i = s.indexOf('o')
int j = s.lastIndexOf('l')
System.out.print(i + " " + j)
}
}
Correct Answer

(C) 4 9