1 import java.util.Scanner; 2 public class TestScanner { 3 public static void main(String[] args) { 4 Scanner scanner = new Scanner(System.in); 5 System.out.println("请输入名字"); 6 String name=scanner.nextLine(); 7 System.out.println("请输入爱好"); 8 String favor=scanner.nextLine(); 9 System.out.println("请输入年龄"); 10 String age=scanner.nextLine(); 11 System.out.println("###################"); 12 System.out.println("姓名:"+name+"爱好:"+favor+"年龄:"+age); 13 scanner.close(); 14 15 16 } 17 }
输出如下: