程序示例:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
System.out.print("请输入你的名字: ");
Scanner in = new Scanner(System.in);
String name = in.nextLine();
System.out.print("请输入你的年龄: ");
int age = in.nextInt();
System.out.printf("Hello, %s, next year you will be %d.", name, age + 1);
}
}
执行结果:
请输入你的名字: 张三
请输入你的年龄: 23
Hello, 张三, next year you will be 24.
格式说明符的语法图:
标签:Scanner,printf,System,year,输入,out From: https://www.cnblogs.com/Chengkai730/p/18442793