What will be the output of the following Java program if input given is “Hello stop World”? [code] class Input_Output {

Nam Lê

Member
What will be the output of the following Java program if input given is “Hello stop World”?
Code:
    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"));
        }
    }
A. Hello
B. Hello stop
C. World
D. Hello stop World
 
Answer: d
Explanation: “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:
Code:
$ javac Input_Output.java
$ java Input_Output
Hello stop World
 

Tìm kiếm

Back
Top