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");
      }
   }

Recommended Answers

All 3 Replies

the loop

 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.