Re: help needed on inputting - tearing hair out .. please!!!




"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


.



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)