问题描述
输入格式
输出格式
样例输入
样例输出
数据规模和约定
代码如下:
import java.util.Scanner;
public class 乘除运算 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextInt();
double b = sc.nextInt();
double c = a/b;
long d=(long) (a*b);
System.out.println(d);
System.out.printf("%.2f",c);
}
}
知识点:
1,java数据类型精度排序:byte<short<long<int<float<double
2,Java中对于int型变量,分配4字节的内存,因此取值范围是-~
-1。也就是说其最大取值为2147483647。而对于long型变量,分配8字节内存,占64位,因此其变量取值范围是-
~
-1。所以此题应该选择使用long,而不是int。
3,输出时保留两位小数:
System.out.printf("%.2f",c);
System.out.println(String.format("%.2f", c));
4,强制类型转换