📜  从键盘 java 代码示例中取一个值

📅  最后修改于: 2022-03-11 14:52:19.894000             🧑  作者: Mango

代码示例1
import java.util.Scanner;

public class Main{
    public static void main(String args[]){

    Scanner scan= new Scanner(System.in);

    //For string

    String text= scan.nextLine();

    System.out.println(text);

    //for int

    int num= scan.nextInt();

    System.out.println(num);
    }
  /*Is better to create another instance of Scanner if you have to use both nextline 
      and nextInt because they can conflict each other
  */
  
}