System.out.println什么意思
时间: 2024-01-18 12:55:46 浏览: 51
System.out.println是Java语言中的一个输出语句,用于将数据或字符串打印到控制台。其中,System是Java的一个标准类库,out是该类库中的一个静态变量,表示标准输出流,println是该类库中的一个方法,表示输出并换行。因此,System.out.println可以将数据或字符串输出到控制台,并在末尾自动添加换行符。
相关问题
java的System.out::println是什么意思
`System.out::println` 是 Java 8 引入的一种新的语法,用于创建一个函数式接口对象。它是对 `System.out.println()` 方法的引用,表示一个无参无返回值的函数式接口,可以用于 Lambda 表达式或方法引用中。
例如,下面的代码使用 Lambda 表达式打印一个字符串:
```
Arrays.asList("Hello", "world").forEach(s -> System.out.println(s));
```
可以使用 `System.out::println` 替换 Lambda 表达式,让代码更简洁:
```
Arrays.asList("Hello", "world").forEach(System.out::println);
```
这种语法也被称为方法引用,可以作为 Lambda 表达式的一种简化写法,提高代码的可读性和简洁性。
利用下面的关键代码编写一个完整的程序KY6_4.java,理解Math类的使用 System.out.println (Math.abs (-5.8)); System.out.println (Math.ceil (3.2)); System.out.println (Math.floor (3.8); System.out.println (Math.round (3.8)); System.out.println (Math.round (3.2)); System.out.println (Math.min (3, 2)); System.out.println (Math.max (Math.PI, 4)); System.out.println (Math.log (7.0)); System.out.println (Math.pow (7,2)); System.out.println (Math.exp (0.4)); System.out.println ("e is:"+ Math.e); System.out.println ("π is:"+Math.PI); System.out.println(Math.random());
以下是完整的程序KY6_4.java,可以运行并输出结果:
```
public class KY6_4 {
public static void main(String[] args) {
System.out.println(Math.abs(-5.8));
System.out.println(Math.ceil(3.2));
System.out.println(Math.floor(3.8));
System.out.println(Math.round(3.8));
System.out.println(Math.round(3.2));
System.out.println(Math.min(3, 2));
System.out.println(Math.max(Math.PI, 4));
System.out.println(Math.log(7.0));
System.out.println(Math.pow(7, 2));
System.out.println(Math.exp(0.4));
System.out.println("e is:" + Math.E);
System.out.println("π is:" + Math.PI);
System.out.println(Math.random());
}
}
```
输出结果:
```
5.8
4.0
3.0
4
3
2
4.0
1.9459101490553132
49.0
1.4918246976412703
e is:2.718281828459045
π is:3.141592653589793
0.3632260047015039
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)