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).
input: -25
output: -25 -23 -21 -19 -17
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
System.out.print("Enter the number: ");
int number = keyBoard.nextInt();
int counter = 0;
do {
if (Math.abs(number) % 2 == 1) {
System.out.print(number + " ");
counter++;
}
number++;
} while (counter < 5);
keyBoard.close();
}
}
Comments
Leave a comment