Write a code that reads integers from the user until the user enters either 0 or 100. Then prints the sum of the numbers entered (excluding the 0 or 100).
import java.util.Scanner;
public class Answer {
public static void main(String[] args) {
System.out.println("Enter number: ");
Scanner scanner = new Scanner(System.in);
int sum = 0;
int a = scanner.nextInt();
while (a != 0 && a != 100){
sum += a;
System.out.println("Enter numbers: ");
a = scanner.nextInt();
}
System.out.println("Sum: " + sum);
}
}
Comments
Leave a comment