Answer to Question #253822 in Java | JSP | JSF for johanes

Question #253822

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
1
Expert's answer
2021-10-23T13:53:03-0400
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();


	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS