I see that many people use java.lang.Scanner.
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
But, I mentioned in some book the code:
class Guess {
public static void main(String args[])
throws java.io.IOException {
char ch, answer = 'K';
System.out.println("I'm thinking of a letter between A and Z.");
System.out.print("Can you guess it: ");
ch = (char) System.in.read(); // read a char from the keyboard
if(ch == answer) System.out.println("** Right **");
}
}
I just wanted to know whats the difference between using the first example and using System.in.read();
Thank you! Also do you need throws java.io.IOException when you want to add user input in your program? What does it do?