Advertisement
n_stefanov

Ex5_AngleUnitConverter

May 14th, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package javaLoopsMethodsClasses;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Ex5_AngleUnitConverter {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         int n = in.nextInt();
  10.         String input = "";
  11.         String measure = "";
  12.  
  13.         for (int i = 0; i <= n; i++) {
  14.             input = in.nextLine();
  15.             input = input.replaceAll("\\s+", "");
  16.             measure = input.replaceAll("\\d+", "");
  17.             measure = measure.replace(".", "");
  18.             input = input.replaceAll("[^0-9.,]+", "");
  19.  
  20.             if (measure.equals("deg")) {
  21.                 System.out.format("%.6f rad%n",
  22.                         degreesToRadians(Double.parseDouble(input)));
  23.             } else if (measure.equals("rad")) {
  24.                 System.out.format("%.6f deg%n",
  25.                         radiansToDegrees(Double.parseDouble(input)));
  26.             }
  27.         }
  28.     }
  29.  
  30.     public static double degreesToRadians(double degrees) {
  31.         double convertedValue = degrees * 0.0174532925;
  32.         return convertedValue;
  33.     }
  34.  
  35.     public static double radiansToDegrees(double degrees) {
  36.         double convertedValue = degrees / 0.0174532925;
  37.         return convertedValue;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement