Answer to Question #245424 in Java | JSP | JSF for RICHARD

Question #245424

v> Write a java programme named AddingNumbers.java that uses a method to sum all

the integers from 10 to 20 but skipping 15 and 16. Invoke the method within the print

command line to print: The sum of all integers from 10 to 20 excluding 15 and 16

is 134.


1
Expert's answer
2021-10-02T01:37:12-0400
public class AddingNumbers {
    public static int sum() {
        int total = 0;
        for (int i = 10; i < 21; i++) {
            if (i < 15 || i > 16) {
                total += i;
            }
        }
        return total;
    }

    public static void main(String[] args) {
        System.out.println("The sum of all integers from 10 to 20 excluding 15 and 16 is " + 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