# GuessWhat- same errors repeated 4 times?

• November 5th, 2009, 08:24 PM
iank
GuessWhat- same errors repeated 4 times?

Code :

```import java.util.Scanner; import java.util.Random; public class GuessWhat { public static void main (String[] args) { { GuessWhat example= new GuessWhat(); example.getRandomNumber(); }     public static void getRandomNumber(); { int min=50; int max=100; Random randGenerator= new Random(); int randomNum=randGenerator.nextInt(max-min+1)+ min; System.out.println("Random number generated is:" + randomNum); } //everything up to this is correct-ask user for guess// Scanner input=new Scanner(System.in); System.out.println (" Please enter another number within the range of fifty through hundred. "); int guess2=input.nextInt(); System.out.println (" Please enter a last number within the range of fifty through hundred. "); int guess3=input.nextInt();   // to show which one is higher //   int guess; int NumberOfGuesses;   NumberOfGuesses=0; guess=0; while(guess!=randomNum && NumberOfGuesses<3) { int guess1=input.nextInt(); System.out.println (" Please enter a number within the range of fifty through hundred. "); if(NumberOfGuesses<6) { if(randomNum>guess) { System.out.println (" Guess is too low. Try a higher number." ); } System.out.println (" Please enter another number within the range of fifty through hundred. "); int guess2=input.nextInt(); if(randomNum<guess) { System.out.println (" Guess is too high. Try a lower number. "); } System.out.println (" Please enter another number within the range of fifty through hundred. "); int guess3=input.nextInt();   }   }   }```
• November 5th, 2009, 08:32 PM
rsala004
Re: GuessWhat- same errors repeated 4 times?
Code :

```public static void getRandomNumber[B]();[/B] { int min=50; int max=100; Random randGenerator= new Random(); int randomNum=randGenerator.nextInt(max-min+1)+ min; System.out.println("Random number generated is:" + randomNum); }```

methods dont end in semicolons

and i am assuming for your purposes you shouldnt be using Static here.

you have an extra { at the top.

you have lots of code outside of a method.

Partial correction, it compiles now but not sure if it does what you expect it too

Code :

```import java.util.Scanner; import java.util.Random; public class GuessWhat { public static void main (String[] args) { //it isn't necessary to create an object of example to run getRandomNumber...since that method is within the class of this method itself. getRandomNumber(); }     public static void getRandomNumber() { int min=50; int max=100; Random randGenerator= new Random(); int randomNum=randGenerator.nextInt(max-min+1)+ min; System.out.println("Random number generated is:" + randomNum);   //everything up to this is correct-ask user for guess// Scanner input=new Scanner(System.in); System.out.println (" Please enter another number within the range of fifty through hundred. "); int guess2=input.nextInt(); System.out.println (" Please enter a last number within the range of fifty through hundred. "); int guess3=input.nextInt();   // to show which one is higher //   int guess; int NumberOfGuesses;   NumberOfGuesses=0; guess=0; while(guess!=randomNum && NumberOfGuesses<3) { int guess1=input.nextInt(); System.out.println (" Please enter a number within the range of fifty through hundred. "); if(NumberOfGuesses<6) { if(randomNum>guess) { System.out.println (" Guess is too low. Try a higher number." ); } System.out.println (" Please enter another number within the range of fifty through hundred. "); guess2=input.nextInt(); if(randomNum<guess) { System.out.println (" Guess is too high. Try a lower number. "); } System.out.println (" Please enter another number within the range of fifty through hundred. "); guess3=input.nextInt();   }   } } }```