Advertisement
Guest User

Untitled

a guest
May 14th, 2014
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class AngleUnitConverter {
  3.    
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         int convertionsCount = Integer.parseInt(input.nextLine());
  7.         String[] commands = new String[convertionsCount*2];
  8.         int lastCommandIndex = 0;
  9.         for(int i = 0 ; i < convertionsCount ; i++){
  10.                String line = input.nextLine();
  11.                String[] lineAsArray = line.split(" ");
  12.                String inputValue = lineAsArray[0];
  13.                commands[lastCommandIndex] = inputValue;
  14.                String typeOfConvertion = lineAsArray[1];
  15.                char[] typeOfConvertionCharArray = typeOfConvertion.toCharArray();
  16.                if(typeOfConvertionCharArray[0]=='r') commands[lastCommandIndex + 1] = "r";
  17.                else commands[lastCommandIndex+1] = "d";
  18.                lastCommandIndex += 2;
  19.             }
  20.         lastCommandIndex = 0;
  21.         for(int i = 0 ;i<convertionsCount; i++){
  22.              if(commands[lastCommandIndex+1]=="r") {
  23.                  System.out.format("%.6f deg", (Math.toDegrees(Double.parseDouble(commands[lastCommandIndex]))));
  24.                  System.out.println();
  25.                  }
  26.              else {
  27.                    System.out.format("%.6f rad",Math.toRadians(Double.parseDouble(commands[lastCommandIndex])));
  28.                    System.out.println();
  29.                }
  30.              lastCommandIndex +=2;
  31.              }
  32.         }
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement