NEW
Font size
WorksheetsJava Strings and lops
Total questions: 10
Worksheet time: 4mins
What is the output of the following?
int x = 9;
if (x>9)
System.out.println("Hello");
else
System.out.println("World");
Hello
World
Syntax Error
Compilation Error
What is the output of the following:
for(int x=1 ; x<5 ; x++){
System.out.print(x);
}
1234
01234
012345
12345
What is the output of the following:
String myWord = "FUN";
String anotherWord = myWord.toLowerCase();
System.out.println(myWord);
fun
Fun
FUN
"fun"
What is the output of the following:
int y = 5;
do{
System.out.println("This is not the output!");
y++;
}while(y>5);
6
Compilation error
This is not the output!
(printed 5 times)
This is not the output!
int x = 25;
if(5*5)
System.out.println("The answer is 25!");
else
Sytem.out.println("The answer is zero");
true
The answer is 25!
The answer is zero
Compilation Error
What is the output of the following?
boolean yes=true, no=false;
if (!yes||no)
System.out.println("maybe");
else
System.out.println("yes!");
no
maybe
Compilation Error
yes!
What is the output of the following?
String a = "I will pass the exams.";
String b = " I will pass the exams. ";
if (a.equals(b))
System.out.println("fail");
else
System.out.println(b.substring(9,12));
pass
fail
Compilation Error
I will pass the exams.
What is the output of the following?
String a = "Are you ready kids?";
String b = "Aye! Aye! Captain!";
System.out.println(a.concat(b));
Are you ready kids? Aye! Aye! Captain!
Compilation Error
Are you ready kids?Aye! Aye! Captain!
Aye! Aye! Captain!
What is the output of the following code?
String a = "19";
String b = "75";
System.out.println(a+" "+b);
19 75
94
Compilation Error
1975
What method of class String is used to remove white spaces at the beginning and end of String objects?
remove()
trim()
concat()
Substring()
