« Back to the main page

Language: Java, Submitted: 6/30/10, Country: Canada - Raw | Download
import java.io.*;

class GuessAge  {

        public static void main(String[] arguments) throws IOException {
                long answ = (Math.round(Math.random() * 100));
                int guess;
                int correct = 0;

                System.out.println("Guess a number between 1 and 100!");
                InputStreamReader converter = new InputStreamReader(System.in);
                BufferedReader in = new BufferedReader(converter);

                while (correct == 0) {

                        guess = Integer.parseInt(in.readLine());
                        if (answ > guess) System.out.println("Too low!");
                        if (answ < guess) System.out.println("Too high!");

                        if (answ == guess) {
                                System.out.println("You got it!");
                                correct = 1;
                        }
                }

        }
}