1.程序:
package InputTest;import java.util.Scanner;public class InputTest021227 {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();String message = String.format("Hello, %s. Next year, you'll be %d",name,(age + 1));System.out.printf(message);}public static void Chiness(){Scanner in = new Scanner(System.in);System.out.print("请输入你的姓名:");String 姓名 = in.nextLine();System.out.print("请输入你的年龄:");int 年龄 = in.nextInt();String message = String.format("你好, %s. 你明年%8.2f岁",姓名,(float)(年龄 + 1));System.out.printf(message);}}
英文运行效果图:
中文运行效果图:
2简化版
String name = "Cay";
int age = 56;
message = String.format("hello, %s . Next year you will be %d",name,(age+1));
System.out.println(message);name = "李一";
age = 20;
message = String.format("你好, %s . 你明年%d岁",name,(age+1));
System.out.println(message);
效果图: