import java.io.*; import java.text.DecimalFormat; public class WinPercentage { /*********************************************************** * Computes the percentage of games won by a team. ***********************************************************/ static BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in)); static final int NUM_GAMES = 12; public static void main (String[] args) throws IOException { int won; double ratio; DecimalFormat fmt = new DecimalFormat ("0.00"); // initialize the loop control variable System.out.print ("Enter the number of games won (0 to " + NUM_GAMES + "): "); won = Integer.parseInt(keyboard.readLine()); while (won < 0 || won > NUM_GAMES) { // invalid input -- initialize the loop control variable System.out.print ("Invalid input. Please reenter: "); won = Integer.parseInt(keyboard.readLine()); } // compute winning percentage ratio = (double)won / NUM_GAMES; // output result to user System.out.println ("\nWinning percentage: " + fmt.format(ratio*100) + "%"); } }