class Number { float num1; float num2; void addition(){ double addition=num1+num2; System.out.println("N1+N2结果为:" + addition); } void subtration(){ double subtration=num1-num2; System.out.println("N1-N2结果为:" + subtration); } void multiplication(){ float multiplication=num1*num2; System.out.println("N1*N2结果为:" + multiplication); } void division(){ float division=num1/num2; System.out.println("N1/N2结果为:" + division); } }
1 import java.util.Scanner; 2 3 public class Number_main { 4 5 public static void main(String[] args) { 6 Number num1=new Number(); 7 Number num2=new Number(); 8 Number num3=new Number(); 9 Number num4=new Number(); 10 11 Scanner input=new Scanner(System.in); 12 System.out.println("输入两个值来计算加减乘除:"); 13 float n1 = input.nextInt(); 14 Scanner input2=new Scanner(System.in); 15 System.out.println("输入第二个值:"); 16 float n2 = input.nextInt(); 17 18 num1.addition(); 19 num2.subtration(); 20 num3.division(); 21 num4.multiplication(); 22 23 } 24 25 }
输入两个值来计算加减乘除:
5
输入第二个值:
4
N1+N2结果为:0.00.0
N1-N2结果为:0.0
N1/N2结果为:NaN
N1*N2结果为:0.0
为什么会出现这样的情况?怎么样才能根据题目做出来,是我的想法有问题吗?
FFIVE
慕勒3428872
犯罪嫌疑人X
白衣染霜花
慕无忌1623718
人到中年有点甜
四季花海
相关分类