Answer to Question #254591 in Java | JSP | JSF for Mike

Question #254591

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

1
Expert's answer
2021-10-23T03:03:52-0400
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);
    }
}

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