Program of adding first ten numbers using the while loop

/*  Program of adding first ten numbers using the while loop */

class AddWhile
{
    public static void main(String args[])
    {
        int j = 1 , sum = 0 ;

        while (j<10)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first ten numbers is : "+sum);
       
        while (j<50)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first fifty numbers is : "+sum);
       
        while (j<100)
        {
            sum = sum + j ;
            j++ ;
        }

        System.out.println("The sum of first hundred numbers is : "+sum);
    }
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|