About the input stream java.util.Scanner referenced in Java

The complete writing is to first import the input stream class Scanner
import java.util .Scanner; then use the input stream, according to the writing name in your question, you should use the Scanner class Scanner input = new Scanner(System.in); // Create Input stream object input int userNum = input.nextInt(); // Use the input stream object to call the nextInt() method to input an integer into userNum, which means to use the nextInt() method in the Scanner class to input an integer, this method just accepts An integer data, if the input is non-integer data, an InputMismatchException exception will be thrown, which is actually an input class specially provided in the imperative interface. The Scanner class is located in the java.util package, among which there are more Other commonly used methods such as : nextLine() Input a line of data, generally treat the data you input as a string nextDouble() Input a double-precision real data nextFloat() Input a single-precision real data nextByte() Input A byte of data nextLong() input a long type of data, etc. If the input is wrong, or the input does not match the method you called, an InputMismatchException exception will be thrown














Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325790340&siteId=291194637