Write a program to find sum of first 10 natural number in java

 Write a program to find sum of first 10 natural number in java

public class Sum
{
    public static void main(String args[]){
        int i , sum=0;
        for(i=0;i<=10;i++){
            sum += i;
        }
        
        System.out.println("Sum of first 10 natural number is "+sum);
    }
   
}

Output
Sum of first 10 natural number is 55

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Calculate Compound Interest in JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java