float a, b;
Scanner input = new Scanner(System.in);
System.out.println("Enter 2 integer");
System.out.println("Enter first integer");
a = input.nextInt();
System.out.println("Enter second integer");
b = input.nextInt();
System.out.println("Calculation the sum, difference, product, quotient "
+ "of 2 integer");
System.out.printf("Sum of 2 integer is: %f\n", a + b);
System.out.printf("Difference of 2 integer is: %f\n", a - b);
System.out.printf("Product of 2 integer is: %f\n", a * b);
System.out.printf("Quotient of 2 integer is: %0.2f\n", a / b);
这是我的代码和程序运行错误。所以我想像这样显示a = 7,b = 5所以a / b = 1.4
答案 0 :(得分:1)
替换
System.out.printf("Quotient of 2 integer is: %0.2f\n", a / b);
与
System.out.printf("Quotient of 2 integer is: %.2f\n", a / b);