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 4 of 4

Thread: Basic loop issue

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Basic loop issue

    I'm new to java programming and I can't figure out how to get this program to do what I want. This is a basic lottery program that asks for 3 numbers between 10 and 99 and then generates three random values to compare to the inputted values. I can't figure out how to successfully compare the random values to the user defined numbers. The program always says "Congratulations you won!" followed by "I'm sorry you didn't win." Any help would be greatly appreciated. The final section of code is:

    public void randomNumbers()
        {
        //choose random values for lottery numbers
        	Random rand = new Random();
     
        	int pick1 = rand.nextInt(90)+ 10;
        	System.out.println("The first lottery number is: " + pick1);
     
        	int pick2 = rand.nextInt(90)+ 10;
        	System.out.println("The second lottery number is: " + pick2);
     
        	int pick3 = rand.nextInt(90)+ 10;
        	System.out.println("The third lottery number is: " + pick3);  	
     
     
        	//compare to entered numbers and print results
     
        	System.out.println("Your numbers were: " + a+", " + b+", " + c);
        	System.out.println("The winning numbers are: " +pick1+", " +pick2+", " +pick3);
     
        	 if (((a== pick1)||(a== pick2)||(a== pick3)) && ((b== pick1)||(b== pick2)||(b== pick3))&&((c== pick1)||(c== pick2)||(c== pick3)));
        	 { System.out.println("CONGRATULATIONS YOU WON!!! ");
     
     
             }else         
       	       System.out.println("I'm sorry you did not win.");
     
     
        }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Basic loop issue

    Hello Nismoz3255, welcome to the Java Programming Forums.

    You have a problem with your if statement. At the end if the if statement you have ;
    Removing this should make it work as expected.

    	    	 if (((a== pick1)||(a== pick2)||(a== pick3)) && ((b== pick1)||(b== pick2)||(b== pick3))&&((c== pick1)||(c== pick2)||(c== pick3)))
    	    	 { 
    	    		 System.out.println("CONGRATULATIONS YOU WON!!! ");	 
    	         }else
    	         {
    	   	       System.out.println("I'm sorry you did not win.");
    	         }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: Basic loop issue

    Haha wow I completely missed that. Thanks so much.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Default Re: Basic loop issue

    No problem
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Java uberNoob, requesting help with simple loop issue
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 08:13 PM
  2. Basic Calculator
    By Yes. in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 4th, 2010, 04:24 PM
  3. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 11:09 AM
  4. Replies: 2
    Last Post: October 29th, 2009, 06:13 PM
  5. Some basic questions.
    By trips in forum Java Theory & Questions
    Replies: 5
    Last Post: July 21st, 2009, 02:15 AM