Results 1 to 5 of 5
  1. #1
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Just joined, I come with a question as well.

    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    
    class apples{
    	public static void main(String args[]){
    		Scanner asy = new Scanner(System.in);
    		Random number = new Random();
    		int guess;
    		int answer;
    		System.out.println("Pick a number between 1 through 10");
    		guess = asy.nextInt();
    		answer = 1+number.nextInt(10);
    		System.out.println("You guessed " + guess + " but the answer is " + answer);
    		System.out.println(guess == answer ? "Congratulations your right!":"");
    		
    	}
    }

    Tried to make a guessing game.
    Guess a number between 1 - 10.
    Is this good? I tried it myself and saw no errors.
    I haven't learned a way to disable the user from using a number above 10 or using letters ect.
    But the program itself should work fine.
    Last edited by Lass; 06-03-2012 at 09:05 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Just joined, I come with a question as well.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: Just joined, I come with a question as well.

    Thanks :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Just joined, I come with a question as well.

    To check the user's input, check the input with a pair of if statements, to see if the input is above or below whatever cut off you desire. If you want to keep asking them until they get it right, use a while loop (I won't tell you the details, but ask that you first try to figure it out).

    I think Darryl's post was to try to get you to change your question heading. "Just joined,... etc" really tells us nothing about your problem other than you have a question -- but we already know that, else you wouldn't be here.

  5. #5
    Lass is offline Member
    Join Date
    Jun 2012
    Posts
    6
    Rep Power
    0

    Default Re: Just joined, I come with a question as well.

    Quote Originally Posted by Fubarable View Post
    To check the user's input, check the input with a pair of if statements, to see if the input is above or below whatever cut off you desire. If you want to keep asking them until they get it right, use a while loop (I won't tell you the details, but ask that you first try to figure it out).

    I think Darryl's post was to try to get you to change your question heading. "Just joined,... etc" really tells us nothing about your problem other than you have a question -- but we already know that, else you wouldn't be here.
    Thanks for the info! I know the while loop details

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2012, 04:00 PM
  2. I finally joined a java forum!
    By drens in forum Introductions
    Replies: 1
    Last Post: 06-10-2010, 10:51 PM
  3. Hello all I joined this forum today
    By psm in forum Advanced Java
    Replies: 4
    Last Post: 04-16-2009, 01:26 PM
  4. Just Joined
    By Shoshana Hartman in forum Introductions
    Replies: 0
    Last Post: 12-23-2008, 02:30 PM
  5. hi today i have joined in the forum
    By nagesh_113 in forum Introductions
    Replies: 1
    Last Post: 07-29-2007, 07:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •