package InputTest;
import java.util.Scanner;
public class InputTest02 {
public static void main(String[] args) {
// English();
Chiness();
}
public static void English(){
Scanner in = new Scanner(System.in);
System.out.print("What is your name?");
String name = in.nextLine();
System.out.print("How old are you?");
int age = in.nextInt();
System.out.printf("Hello, %s. Next year, you'll be %d",name,(age + 1));
}
public static void Chiness(){
Scanner in = new Scanner(System.in);
System.out.print("请输入你的姓名:");
String 姓名 = in.nextLine();
System.out.print("请输入你的年龄:");
int 年龄 = in.nextInt();
System.out.printf("你好, %s. 你明年 %d 岁",姓名,(年龄 + 1));
}
}
英文运行效果图:
中文运行效果图:
ps:
f
是浮点数,s
是字符串,d
是整型,%.2f
可以指定精度,%8.2f
可以额外指定字符宽度,确定精度后宽度不足前面会用空格占位补至指定宽度