Menu
Question Index
...

What will be output of the following program? Assume that input is entered as 'Hello Hai' at a time.

import java.util.*;
public class ScannerExample {
    public static void main(String arg[]) {
        String str = "Indians are the champions";
        Scanner sc = new Scanner(System.in);
        str = sc.next();
        System.out.println(str);
        str += sc.next();
        System.out.println(str);
    }
}


Hai
HaiHello
HaiHello
HaiHello
Hai
Hello
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Scanner Class Constructors With Example

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App