Sail E0 Webinar
Question


What is the output of this program if input given is "Hello stop World"?


class Input_Output {
public static void main(String args[]) throws IOException {
string str;
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
do {
str = (char) obj.readLine();
System.out.print(str);
} while(!str.equals("strong"));
}
}
Options:
A .  Hello
B .  Hello stop
C .  World
D .  Hello stop World
Answer: Option D

"stop" will be able to terminate the do-while loop only when it occurs singly in a line. 

"Hello stop World" does not terminate the loop.
Output:
$ javac Input_Output.java
$ java Input_Output
Hello stop World



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers