Answer to Question #242714 in Java | JSP | JSF for java

Question #242714

 Write a program called AnyHellos. This program should prompt the user for an integer n, then should print the phrase "Hello World" n times. You may assume that n will never be negative. Here is an example of what the program output should look like (user input is in orange bold italics):

How many hellos? 

5

Hello World

Hello World

Hello World

Hello World

Hello World

Your program should run with ANY positive integer n given as input.

NOTE: Place the user input on the new line (just use println in your prompt).


1
Expert's answer
2021-09-26T21:02:34-0400
import java.util.Scanner;

public class AnyHellos {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("How many hellos?");
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            System.out.println("Hello World");
        }
    }
}

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