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);
    }
}
Share This :

Related Post

avatar
Anonymous

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

delete 28 January 2022 at 15:08



sentiment_satisfied Emoticon