6)
Which package should be imported to use Scanner class?
- import java.util.System.in;
- import java.util.Scanner;
- import java.util.System;
- import java.util.Input;
Correct Answer: 2
import java.util.Scanner;
7)
Consider the given code snippet, What will following code do?
char ch;
Scanner SC=new Scanner (System.in);
ch=SC.nextChar();
- Read a single character
- Read a string
- Read string but store single character
- Error
Correct Answer: 4
Error
nextChar() is not a method of Scanner class.
8)
What will be printed by following code snippet, if input value is Hello World!?
Scanner scanner = new Scanner();
String str;
str = scanner.next();
System.out.print(str);
- Compilation Error
- Hello World!
- Hello
- None of these
Correct Answer: 3
Hello
next() method does not store characters after space.