// 示例代码:使用 println 在 Java 中打印输出
public class PrintlnExample {
public static void main(String[] args) {
// 打印字符串
System.out.println("Hello, World!"); // 输出: Hello, World!
// 打印整数
int num = 42;
System.out.println(num); // 输出: 42
// 打印浮点数
double pi = 3.14159;
System.out.println(pi); // 输出: 3.14159
// 打印布尔值
boolean isTrue = true;
System.out.println(isTrue); // 输出: true
// 打印多个值,用逗号分隔
System.out.println("The value of pi is " + pi + " and the number is " + num);
// 输出: The value of pi is 3.14159 and the number is 42
}
}
System.out.println() 是 Java 中用于在控制台打印输出的常用方法。println 会在输出内容后自动换行。+ 运算符进行字符串拼接。上一篇:java list遍历删除
下一篇:java hashmap初始化
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站