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
Get step-by-step solutions from verified subject matter experts
