使用Java写出:给定两个浮点数,输出它们的和,差,积。
时间: 2023-06-03 10:02:37 浏览: 235
JAVA中浮点数的运算
好的,这是一个计算问题,可以回答。下面是使用Java实现的示例代码:
```java
public class Calculation {
public static void main(String[] args) {
double num1 = 2.5;
double num2 = 1.8;
double sum = num1 + num2;
double diff = num1 - num2;
double product = num1 * num2;
System.out.println("Sum: " + sum);
System.out.println("Difference: " + diff);
System.out.println("Product: " + product);
}
}
```
运行结果如下:
```
Sum: 4.3
Difference: 0.7
Product: 4.5
```
希望能对您有所帮助!
阅读全文