Untitled
unknown
plain_text
2 years ago
554 B
10
Indexable
/**
* 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);
}
}
Editor is loading...
Leave a Comment