In training materials from ElementK, I observed the use of System.in.read() to accept input from the keyboard. In my intro to Java class, I was taught to use the Scanner class in Java. What is the different between these two methods?
I’ll talk about the Scanner class although the Java API docs do a much better job of clarification. If you want to create a simple Java program where the user is prompted to enter words, characters or numbers, you need a class that allows you to do this. The Scanner class does not belong to the java.lang package to you need to import the Scanner class from java.util.Scanner using the import command at the top of your Java class.