Simple usage of the Scanner class in Java
- 2020-04-01 02:45:57
- OfStack
public static void main(String[] args) {
System.out.println(" Please enter a value to end with press enter: ");
Scanner sc = new Scanner(System.in);
sc.useDelimiter("n");
while (sc.hasNext()) {
String s = sc.next();
System.out.println(" Get the value: "+s);
}
}
1. Use Scanner class to encapsulate system. In input stream
2. Sc. UserDelimiter (" \ n "); Sets the end of the input flag and ends with a enter.
3. Use sc.hasnext () to determine if there is any content, and sc.next() to extract it