第一次在这里发帖,对格式感到抱歉。
public static void main(String args[]) {
float x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextFloat();
y = in.nextFloat();
z = x + y;
System.out.println("Sum of entered integers = "+z);
}
public static void main1(String args[]) {
int x, y, z;
System.out.println("Enter two integers to calculate their sum ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = x + y;
System.out.println("Sum of entered integers = "+z);
}
}
我需要帮助方法重载让我的程序添加整数和浮点数,例如 4 和 5 = 9
4.0 和 5.0 = 9.0
但是到目前为止,即使我只是输入带有 int 值的数字,我的输出也只给了我浮点值。