一:
在python里直接使用input函数就可以,在java里,需要使用Scanner类,用System.in进行初始化,获取用户输入可以用nextLine获取字符串,nextInt获取整形数据。
1 import java.util.Scanner; 2 3 public class print_In { 4 public static void main(String[] args){ 5 System.out.println("what is your name?"); 6 Scanner scan= new Scanner(System.in); 7 String name=scan.nextLine(); 8 System.out.println(name); 9 System.out.println("how old are you?"); 10 Integer age=scan.nextInt(); 11 System.out.println(age); 12 } 13 } 14 15 what is your name? 16 evil 17 evil 18 how old are you? 19 2 20 2
时间: 2024-12-29 11:48:31