Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
554 B
1
Indexable
Never
/**
 * A For and While loop that will provide the sum of all the integers 1 to 100 inclusive
 *
 * @author Amanda Cui
 * @version 11/14/23
 */
public class Gauss
{
    public static void main(String[] args){
        //For loop
        int sum = 0;
        for (int i=1;i<=100;i++){
            sum+=i;
        }
        System.out.println(sum);
        
        //While loop
        int x=1;
        int sum2=0;
        while (x<=100){
            sum2+=x;
            x++;
        }
        System.out.println(sum2);
    }
}
Leave a Comment