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).
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");
}
}
}
Comments
Leave a comment