阅读量:0
在Java中,你可以使用System.out.println()
方法来输出多个变量。将变量用逗号分隔,并放在括号内。例如:
public class Main { public static void main(String[] args) { int a = 10; double b = 3.14; String c = "Hello"; System.out.println("a = " + a + ", b = " + b + ", c = " + c); } }
这段代码会输出:
a = 10, b = 3.14, c = Hello
你也可以使用printf()
方法来格式化输出。例如:
public class Main { public static void main(String[] args) { int a = 10; double b = 3.14; String c = "Hello"; System.out.printf("a = %d, b = %.2f, c = %s%n", a, b, c); } }
这段代码会输出:
a = 10, b = 3.14, c = Hello