I need to stop asking for integer inputs when zero is typed as an input and start summation immediately. My program doesn't stop when I type zero. I need it to stop and start summing up all the inputs it has gathered.
Here is what I have:
public class Inttosum {
public static void main(String[] args) {
System.out.println("Enter an integer");
Scanner kb = new Scanner(System.in);
int askool = kb.nextInt();
int sum = 0;
int score = 0;
while(askool != 0){
score = kb.nextInt();
sum += score;
}
}
}
/////////////////The final code which worked..Thank you! public class Inttosum {
public static void main(String[] args) {
System.out.println("Enter an integer");
Scanner kb = new Scanner(System.in);
int sum = 0;
int score = 0;
do {
score = kb.nextInt();
sum += score;
}while(score != 0);
System.out.print(sum);
}
}