java Scanner loop input

Purpose of this article

I always forget it, so my memo

Contents

I want to input with Scanner in Java and loop the input until the desired numerical value and character string are input. Don't think about exception handling, just a memo for processing.

code

rupe.java


Scanner scan = new Scanner(System.in);
while(true){
  int num = scan.nextInt();
  switch(num){
    case //Numerical value you want to enter:
      //Processing content
      break;
    default:
      continue;
  }
  break;
}

Recommended Posts

java Scanner loop input
java Scanner class
[java.io] Summary of Java string input (InputStream, Reader, Scanner)
Input to the Java console
Talk about using Java input wait (Scanner) in VS Code
Very simple input reception in Java
[Java] Loop processing and multiplication table
How slow is a Java Scanner?
scanner
[Java] Input to stdin of Process
Java
Java
Story of paiza.jp [Java standard input solution]
Study Java Try using Scanner or Map
Receive joystick input in Java LW JFL
How to use Java Scanner class (Note)
Console input in Java (understanding the mechanism)