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).
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);// create Scanner object
int number=0;
System.out.print("Enter a number: ");
number = input.nextInt();
int counter=0;
System.out.println("A list 5 odd numbers above the given number: ");
do {
if(number%2==1) {
System.out.println(number);
counter++;
}
number++;
}while(counter<5);
input.close();
}
}
Comments
Leave a comment