import java.io.*; import java.text.DecimalFormat; import java.util.Scanner; public class WinPercentage { /*********************************************************** * Computes the percentage of games won by a team. ***********************************************************/ 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 = scan.nextInt(); while (won < 0 || won > NUM_GAMES) { // invalid input -- initialize the loop control variable System.out.print ("Invalid input. Please reenter: "); won = scan.nextInt(); } // compute winning percentage ratio = (double)won / NUM_GAMES; // output result to user System.out.println ("\nWinning percentage: " + fmt.format(ratio*100) + "%"); } }