Question: Modify the program to use the do-while instead which outputs exactly the same. Submit a screen shot of the execution of the modified code demonstrating

Modify the program to use the do-while instead which outputs exactly the same. Submit a screen shot of the execution of the modified code demonstrating that it works exactly the same as the original for the same input.

 

import java.util.Scanner;

public class MyClass {
   public static void main(String args[]) {
       // define variable to store user input
       int n;
       Scanner sc = new Scanner(System.in);
       
       // take user input
       System.out.println("Enter number of times to loop: ");
       n = sc.nextInt();
       
       // declare int variable to iterate
       int i;
       
       // iterate using for loop for n times
       // from i = 0 till i = n-1 and print
       // value of (i+1)
       for(i = 0; i < n; i++) {
           System.out.println("Iteration number: " + (i+1));
       }
   }
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!