Sum Of Natural Numbers Using FOR Loop | Java Programs

Output:

*** Sum Of Natural Numbers Using FOR Loop ***

For lOOp used !!!

Sum of first 10 natural numbers is: 55

Click Here For Java Online Compiler

Solution:

public class SumNaturalForLoop {

    public static void main(String[] args) {

        int num = 10; // <------ How many numbers???
        int count;
        int total = 0;

        for (count = 1; count <= num; count++) {
            total = total + count;
        }
        System.out.println("*** Sum Of Natural Numbers Using FOR Loop ***" + "\n");
        System.out.println("For lOOp used !!!" + "\n");
        System.out.println("Sum of first 10 natural numbers is: " + total);
    }
}

Comments

  1. Is The Coin Casino Safe? | Casinoworld
    Coin Casino is one of the most reputable 인카지노 and reputable gambling sites for kadangpintar cryptocurrencies. 1xbet Check out our review of their games, games, bonuses, security and

    ReplyDelete

Post a Comment

Popular posts from this blog

Print Number Pattern - 10 | Java Programs

Print your name in Java | Java Programs

Print Number Pattern - 9 | Java Programs