【发布时间】:2014-06-14 08:20:19
【问题描述】:
我正在用 java 制作一个计算器,类似于我们计算机上的计算器。我一直在尝试复制这种情况。
电脑计算器:
5 / 2 = 2.5 * 2 = 5
所以基本上..
int/int = double * int = int
它是如何工作的?大声笑,我能做的最接近的事情是:
int num_1 = 5;
int num_2 = 2;
double ans = (double) num_1/num_2;
double num_1 = ans;
int num_2 = 2;
int ans = num_1*num_2;
但我无法重新声明变量名,所以我该如何编程...哈哈
如果这有帮助,我的程序中有 3 个变量:
int currentValue // value displayed when number key is pressed *** eg: 2, 3, etc
int runningValue // value of running total *** eg: 2 + 2 + (right now a runningValue of 4 is shown on the computer calculator)
int finalValue // value given when the equal sign is pressed 5 + 5 = 10
帮助?
【问题讨论】:
-
如果您的问题是关于 Java 的,请不要添加 C 或 C++ 标签。
-
为什么要再次声明变量,您只需将值分配给该变量即可。
标签: java calculator type-conversion