Answer to Question #339131 in Java | JSP | JSF for rose

Question #339131

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).




1
Expert's answer
2022-05-10T13:22:46-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS