System.out.printf

程序示例:

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.

格式说明符的语法图:

posted @ 2024-10-01 12:09  有空  阅读(107)  评论(0)    收藏  举报