//################################################################ // // Radians2Degrees.java // // // Sample Run: // // Enter an Angle in Radians: 2 // 2.0 radians = 114 degrees, 35 minutes, 29 seconds. // // How Does It Work: // 2 radians = 114.591559.. degrees = (2.0 / PI)*180.0 // // That is 114 degrees + 0.591559 in change. // To convert this remainder into second we must divide it by 1.0/60.0 // 0.591559 / (1.0/60.0) = 0.591559 * 60.0 = 35.4935415 // // Thus, we are left with 35 minutes + 0.4935415 in change. // To get the number of seconds we do the same thing // 0.4935415 / (1.0/60.0) = 0.4935415 * 60.0 = 29.61249 // // Therefore, 2.0 radians = 114 degrees, 35 minutes, 29 seconds // // Sanity check: // 114 + (35* 1.0/60.0) + (29 * 1.0/60.0 * 1.0/60.0) = 114.5913889 // (114.5913889 / 180.0) * PI = 1.999997031 radians // //################################################################ import java.util.Scanner; public class Radians2Degrees { public static void main (String[] args) { Scanner scan = new Scanner(System.in); // Ask the user for input System.out.print("Enter an Angle in Radians: "); double radians = scan.nextDouble(); // Calculate the degrees double degrees = (radians/Math.PI) * 180.0; int deg = (int) Math.floor(degrees); // Calcualate the minutes double minutes = 60.0 * (degrees - deg); int min = (int) minutes; // Calculate Seconds double seconds = 60.0 * (minutes - min); int sec = (int) seconds; System.out.print(radians + " radians = "); System.out.print(deg + " degrees, "); System.out.print(min + " minutes, "); System.out.print(sec + " seconds.\n"); System.out.println("\nSanity Check:"); double degrees2 = deg + min*(1.0/60.0) + sec*(1.0/60.0)*(1.0/60.0); double radians2 = (degrees2/180.0)* Math.PI; System.out.println("Converting back to radians we get: " + radians2); System.out.println("The difference is: " + (radians - radians2)); } }