Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: GuessWhat- same errors repeated 4 times?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question GuessWhat- same errors repeated 4 times?

    I don't understand the same 4 errors. please help me. thank you. i appreciate everyone's help.


    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();
     
       }
     
     }
     
    }
    Last edited by helloworld922; November 5th, 2009 at 08:18 PM. Reason: Please put [code] tags around your code!


  2. #2
    Member
    Join Date
    Jul 2009
    Posts
    31
    Thanks
    3
    Thanked 6 Times in 5 Posts

    Default Re: GuessWhat- same errors repeated 4 times?

    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

    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();
     
    }
     
    }
    }
    }
    Last edited by rsala004; November 5th, 2009 at 07:38 PM.

Similar Threads

  1. Errors with LispList
    By Newoor in forum Collections and Generics
    Replies: 10
    Last Post: October 25th, 2009, 04:25 PM
  2. [SOLVED] Error of "cannot find symbol"
    By big_c in forum File I/O & Other I/O Streams
    Replies: 31
    Last Post: April 9th, 2009, 11:20 AM
  3. Ambiguity and non-static variable reference error in java
    By jenseits in forum AWT / Java Swing
    Replies: 5
    Last Post: December 8th, 2008, 06:04 PM