Exercise
Repetitive structures
Objetive
Write a java program that prompts the user for two numbers and displays the numbers between them (inclusive) three times using "for", "while", and "do while" loops.
Enter the first number: 6
Enter the last number: 12
6 7 8 9 10 11 12
6 7 8 9 10 11 12
6 7 8 9 10 11 12
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int number, number2;
int i;
System.out.print("Enter first number: ");
number = Integer.parseInt(new Scanner(System.in).nextLine());
System.out.print("Enter last number: ");
number2 = Integer.parseInt(new Scanner(System.in).nextLine());
for (i = number; i <= number2; i++)
{
System.out.printf(i);
}
System.out.println();
i = number;
while (i <= number2)
{
System.out.printf(i);
i++;
}
System.out.println();
i = number;
do
{
System.out.printf(i);
i++;
} while (i <= number2);
System.out.println();
}
}