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

Thread: I'm lost

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I'm lost

    I'm trying to make a guessing game that I can log the number in from the keyboard. Then let random guess
    my number,and continue until it finds the answer.A little Help will be great.
    import java.util.Scanner;
    import java.util. Random;
     
     
    public class hellobaby {
     
    	   public static void main(String[] args, Scanner myScanner) {
     
     
     
       Scanner eyes =new Scanner(System.in);
       int kguess;
       kguess = eyes .nextInt();
    	 System .out.println("input your number"+kguess);
    	   }  
     
     
     
     
     
     
     
    		boolean shouldLoopEnd = false;{
     
     
    		for (int counter=1;counter <=10;counter++);
    	     //generate a random number 
    		Random dice = new Random ();			
     
    	     myScanner = dice.nextInt(6);
     
    			System.out.println = ("The target number is: " + myScanner);}
     
     
    	     while (true) 
    	     {
     
    	       int guessNumber = (int) (Math.random() * 100);
    	       System.out.println ("The loop guesses: " + guessNumber);
     
     
    	       if (guessNumber ==  guessNumber  ) 
    	       {
    	         shouldLoopEnd = true;
    	       }
     
     
    	       if (shouldLoopEnd == true)       {
    	         System.out.println ("Woo hoo! We have a match!");
    	         break; // break loop
    	       } 
    	       else 
    	       {
    	         //around the loop we go again
    	         System.out.println ("Let's try again..");
    	       } 
    	     }
    	   }
    	 }
    		}
    Attached Files Attached Files
    Last edited by copeg; August 27th, 2010 at 11:15 PM. Reason: Please use the code tags


  2. #2
    Member
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    10
    Thanked 3 Times in 3 Posts

    Default Re: I'm lost

    hi stoptheerrors,

    A quick glance at your code reveals many problems. A few things catch my eye right away. First, I've never seen a main with a parameter other than args. The command line arguments are put into the String array args. I wouldn't even know how to supply arguments to main other than the command line. Maybe someone more experienced has and can explain, but personally, I've never seen it. Therefore, I would change it to:

    public static void main(String[] args) {

    Second, it looks like you have code which is not in a method inside your class. You will probably want to put this into a method somehow:
    public void myMethod(){
    //your code here... for loops, etc...
    }

    Also, your for loop basically does nothing. You are probably trying to do this:

    for (int counter=1;counter <=10;counter++){
    //your code here
    }

    What is this code supposed to do:

    if (guessNumber == guessNumber )

    It looks like you are checking if a value equals itself. Well, I don't see why it wouldn't.

    Your variable declaration should look like this (without the { at the end):

    boolean shouldLoopEnd = false;

    Anyway, that's just a few things. I'd pick up a Java book if possible; I think it would really help you with the basics.

  3. The Following User Says Thank You to bbr201 For This Useful Post:

    JavaPF (August 31st, 2010)

  4. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I'm lost

    I took your advise.Thanks!!

Similar Threads

  1. [SOLVED] java Reflection Question - I am lost.
    By prain in forum Java Theory & Questions
    Replies: 3
    Last Post: May 13th, 2010, 02:43 PM
  2. lost
    By nyny in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 7th, 2010, 07:32 AM
  3. Completely Lost in this problem(multiple methods)
    By wacarter in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 31st, 2010, 04:44 PM
  4. Need Help! I'm completly lost!
    By DeMolay8613 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 11th, 2010, 01:21 PM
  5. please could you help me with this java problem im very lost
    By eyeore in forum Java Theory & Questions
    Replies: 4
    Last Post: September 7th, 2009, 09:19 AM