Padd Solutions

Converted by Falcon Hive

import java.util.Scanner;

public class Guess
{
    public static void mai (String[] args)
    {
        Scanner scan = new Scanner (System.in);
       
        int counter = 0;
        int guess;
        int random = (int)(Math.random () * 10 + 1);
       
        System.out.print ("Guess my number: ");
        guess = scan.nextInt ();
       
        while (guess != random)
        {
            counter++;
           
            System.out.print ("Try again? ");
            guess = scan.nextInt ();

        }
       
        System.out.println ("Congratulations! You finally guessed the number! It took you "+counter+" tries!");
    }
}

(0) Comments

Post a Comment