Using a do-while loop create a program that will prompt the user for a number and then print out a list 5 odd numbers above the given number(inclusive).
Sample Run1
Enter a number:Â 10
Output1: 11 13 15 17 19
Sample Run2
Enter a number: 5
Output2:Â 5 7 9 11 13
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = in.nextInt();
int counter = 0;
do {
if (number % 2 != 0) {
System.out.print(number + " ");
counter++;
}
number++;
} while (counter < 5);
}
}
Comments
Leave a comment