Advertisement
coasterka

#3AngleUnitConverter

May 14th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.ArrayList;
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Locale;
  6. import java.util.Scanner;
  7.  
  8. public class AngleUnitConverter {
  9.     public static void main(String[] args) {
  10.         Locale.setDefault(Locale.ROOT);
  11.         Scanner scan = new Scanner(System.in);
  12.         System.out.println("How many numbers will you enter?");
  13.         int n = scan.nextInt();
  14.         scan.nextLine();
  15.         String[] strings = new String[n];
  16.         double[] numbers = new double[n];
  17.         for (int i = 0; i < numbers.length; i++) {
  18.             numbers[i] = scan.nextDouble();
  19.             strings[i] = scan.next();
  20.             scan.nextLine();
  21.             convertAngles(numbers[i], strings[i]);
  22.         }      
  23.     }
  24.  
  25.     private static void convertAngles(double number, String str) {
  26.         DecimalFormat decPoints = new DecimalFormat("#.000000");
  27.         if (str.equals("deg")) {
  28.             number *= 0.0174532925;
  29.             String convertedValue = decPoints.format(number);
  30.             System.out.println(convertedValue + " rad");
  31.         }
  32.         if(str.equals("rad")){
  33.             number *= 57.2957795;
  34.             String convertedValue = decPoints.format(number);
  35.             System.out.println(convertedValue + " deg");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement