Answer:
public class Main{
public static void main(String[] args) {
//The While Loop
int i = 1;
int sum = 0;
while(i <=10){
sum+=i;
i++; }
System.out.println("Sum: "+sum);
//The for Loop
int summ = 0;
for(int j = 1;j<=10;j++){
summ+=j; }
System.out.println("Sum: "+summ); } }
Explanation:
The while loop begins here
//The While Loop
This initializes the count variable i to 1
int i = 1;
This initializes sum to 0
int sum = 0;
This while iteration is repeated until the count variable i reaches 10
while(i <=10){
This calculates the sum
sum+=i;
This increments the count variable i by 1
i++; }
This prints the calculated sum
System.out.println("Sum: "+sum);
The for loop begins here
//The for Loop
This initializes sum to 0
int summ = 0;
This iterates 1 through 10
for(int j = 1;j<=10;j++){
This calculates the sum
summ+=j; }
This prints the calculated sum
System.out.println("Sum: "+summ); }