基本上,我有一部手机是在这款名为BlueJ的应用中制作的。它会输入电话通话的持续时间,然后您就可以插入点数。每分钟等于一磅。所以基本上,如果我插入5磅和6分钟,它会做6-5。
在这种情况下,它不起作用。
信用是成功的,但随着信用的变化,持续时间从新的信用中减去,而不是从输入的信用中减去。
有没有办法绕过这一点,或者同时运行它,或者在旧值发生变化之前运行它?
问题是它在哪里说:
credit = credit - duration;
duration = duration - credit;非常感谢。
public void makePhoneCall()
{
if(credit == 0)
System.out.println("Insert more than 0 credit to make a phone call!");
else {
if(credit >= duration) {
System.out.println("The phone number " + number + " is being dialed for " + duration + " minutes");
credit = credit - duration;
duration = duration - credit;
}
else {
if(credit < duration)
System.out.println("You do not have enough credit to make a phone call! Your credit is " + credit + " pounds");
}
}发布于 2016-12-13 03:45:24
我不确定我是否理解了你想要做的事情,但我的理解是:
使用credit = credit - duration;,您正在重新定义“信用”的价值。但是您想要减去下面这行中"credit“的原始值。
在修改该值之前,可以简单地将其存储在另一个变量中,如下所示:
int oldCredit = credit;
credit = oldCredit - duration;
duration = duration - oldCredit;https://stackoverflow.com/questions/41108223
复制相似问题