0

my problem is asking me to write a program that reads a value (say n) from the user and outputs Hello World n times. Verify that the user has entered an integer. If the input is 3, the output will be Hello World printed three times.

I have gotten this far and i hope it is correct but once i get the number from the user it will not print Hello World that number of times what steps am i missing?
Thanks in advance

  import java.util.Scanner;

   public class HelloWorld
   {
      public static void main (String[] args)
      {
         Scanner scan = new Scanner( System.in);

         System.out.println("Enter a number as a integer");
         {

         }
         int x = scan.nextInt();

         System.out.println("Hello World");
      }
   }
4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by stultuske
0
 System.out.println("Enter a number as a integer");
          {
          }

I'm also not sure what you are trying to do with those brackets, but it's best to remove them. they don't actually do anything, but make your code a little less readable, especially if you're just starting in Java.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.