Re: help needed on inputting - tearing hair out .. please!!!
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Mon, 28 Nov 2005 20:12:39 GMT
"patrick_woflian" <gingercrock@xxxxxxxxxxx> wrote in message
news:1133199159.304302.322790@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> import java.util.Scanner;
> import java.util.Random;
>
>
> public class dice
> {
> public static void main (String [] args)
> {
> Scanner in = new Scanner(System.in);
>
> Random rnd = new Random();
>
>
> int correctguesses;
> correctguesses = 0;
>
> int r = rnd.nextInt(12) + 1;
>
> System.out.print("guess a number ");
> int x = in.nextInt();
>
> if (x != r)
>
> System.out.print(" Do you think the next number will be higher HI or
> lower LO than " + x );
>
> int y = in.nextInt();
> String guess = in.next();
>
> boolean correct = false;
> if (guess.equals("HI"))
> {
> correct = ( x > y);
> }
> else if (guess.equals("LO"))
> {
> correct = (x < y);
> }
> System.out.println("The number was " + x + " and you guessed " + y +
> " so you " + (correct ? "ROCK!" : "SUCK!"));
>
>
>
>
> }
>
> }
>
> this is the program in its full, i am trying to capture input from the
> text file.. thanks very much for your help
I don't know what file you'r referring to, but your program compiles
without error. As for running it... well... it might not do exactly what you
intend (but then again, you haven't said what you intend for it to do).
I'll just point out that your program seems to be expecting the user to
enter in 2 integers in a row, but the prompts displayed to the user give no
indication of this.
In other words, the program asks me to "guess a number", so I do (I
guessed '3'), and then it asks me "Do you think the next number will be
higher HI or lower LO than 3", so I type in "HI", but the program throws an
exception 'cause it was actually expecting me to enter in an integer, as
seen on the line "y = in.nextInt();".
- Oliver
.
- Follow-Ups:
- Re: help needed on inputting - tearing hair out .. please!!!
- From: patrick_woflian
- Re: help needed on inputting - tearing hair out .. please!!!
- References:
- help needed on inputting - tearing hair out .. please!!!
- From: patrick_woflian
- Re: help needed on inputting - tearing hair out .. please!!!
- From: Michael Redlich
- Re: help needed on inputting - tearing hair out .. please!!!
- From: patrick_woflian
- help needed on inputting - tearing hair out .. please!!!
- Prev by Date: Re: read keyboard input and storing in an array?
- Next by Date: Capturing sound over SB (What you hear)
- Previous by thread: Re: help needed on inputting - tearing hair out .. please!!!
- Next by thread: Re: help needed on inputting - tearing hair out .. please!!!
- Index(es):
Relevant Pages
|