Answer the question
In order to leave comments, you need to log in
Why can't a variable be subtracted inside a while?
import java.util.*;
class Practice2{
static Scanner eva = new Scanner(System.in);
public static void main(String[] args) {
int x, y,over,account;
over = eva.nextInt();//овер(максимально допустимый "минус")
account = eva.nextInt();// общий счёт потребителя
while(account >= over) {
x = eva.nextInt();// если положителььное число, то +, иначе -
if(x<0)
account-=x;
else
account+=x;
System.out.println("Ваш текущий счёт : "+account);
}
}
}
Answer the question
In order to leave comments, you need to log in
Because the computer does what you told it to do, not what you want it to do :)
Let account = 100
then if x=10
account = 100 + 10 = 110
then if x = -5
account = 110 - (- 5) = ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question