@@ -29,29 +29,24 @@ public static void main(String[] args) {
2929 feet = inches / IN_PER_FOOT ;
3030 remainder = inches % IN_PER_FOOT ;
3131 inches = inches - (feet * IN_PER_FOOT );
32- System .out .printf ("%.2f cm = %fd ft, %d in\n " , cm , feet , inches );
32+ System .out .printf ("%.2f cm = %d ft, %d in\n " , cm , feet , inches );
3333 }
34- } else if (choice == 2 ); {
34+ } else if (choice == 2 ) {
3535 System .out .print ("Enter feet: " );
3636 feet = in .nextInt ();
3737 System .out .print ("Enter inches: " );
3838 inches = in .nextInt ();
3939
4040 if (feet < 0 || inches < 0 || inches >= IN_PER_FOOT ) {
4141 System .out .println ("Please enter valid and positive values for feet and inches." );
42+ } else {
43+ cm = (feet * IN_PER_FOOT + inches ) * CM_PER_INCH ;
44+ System .out .printf ("%d ft, %d in = %.2f cm\n " , feet , inches , cm );
4245 }
46+ } else {
47+ System .out .println ("Invalid choice, please enter 1 or 2." );
4348 }
4449
45- // prompt the user and get the value
46- System .out .print ("Exactly how many cm? " );
47- cm = in .nextDouble ();
48-
49- // convert and output the result
50- inches = (int ) (cm / CM_PER_INCH );
51- feet = inches / IN_PER_FOOT ;
52- remainder = inches % IN_PER_FOOT ;
53- System .out .printf ("%.2f cm = %d ft, %d in\n " ,
54- cm , feet , remainder );
5550 }
5651
5752}
0 commit comments