Snippets tagged “scanner”
11 snippets use this tag.
- Getting Keyboard InputJava
To get keyboard input in Java, you can use the Scanner class from the java.util package.
- How do I read / convert an InputStream into a String in Java?Java
There are several ways to read an InputStream and convert it to a String in Java. One way is to use the BufferedReader and InputStreamReader classes to read the InputStream line by line, and use a StringBuilder to construct the final String:
- How to get the user input in Java?Java
To get user input in Java, you can use the Scanner class. Here's an example of how to get a string input from the user:
- How to put a Scanner input into an array... for example a couple of numbersJava
To put input from a Scanner into an array in Java, you can use a loop to read the input and store it in the array.
- How to read file from relative path in Java project? java.io.File cannot find the path specifiedJava
To read a file from a relative path in a Java project, you can use the File class from the java.io package and specify the relative path to the file.
- How to read integer value from the standard input in JavaJava
To read an integer value from the standard input (keyboard) in Java, you can use the Scanner class from the java.util package.
- Java: How to get input from System.console()Java
To get input from the System.console() in Java, you can use the readLine() method of the Console class.
- Scanner is skipping nextLine() after using next() or nextFoo()?Java
It is common for the Scanner class's next() and nextFoo() methods (where Foo is any primitive type such as Int, Double, etc.) to skip over newline characters in the input. This is because these methods are designed to read only the next token in the input
- Split Java String by New LineJava
To split a string in Java by new line, you can use the split method of the String class and pass it the regular expression "\n" or "\r\n", depending on the platform you are running on.
- Take a char input from the ScannerJava
To take a character input from the Scanner in Java, you can use the next() method to read a string and then use the charAt(int index) method to get the first character of that string. Here's an example:
- Using scanner.nextLine()Java
Scanner.nextLine() is a method of the Scanner class in Java that reads a line of text from the input.