Advertisement
Guest User

Untitled

a guest
May 16th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class _05_Angle_Unit_Converter {
  8.  
  9. public static String radToDegreesAndOpp(double rads_degs, String type)
  10. {
  11. String returnValue;
  12. DecimalFormat df = new DecimalFormat("#.000000");
  13.  
  14. if (type=="rad")
  15. {
  16. double degrees=Math.toDegrees(rads_degs);
  17.  
  18. returnValue=df.format(degrees)+" "+"deg";
  19. }
  20. else
  21. {
  22. double radians=Math.toRadians(rads_degs);
  23.  
  24. returnValue=df.format(radians)+" "+"rad";
  25. }
  26. return returnValue;
  27.  
  28.  
  29. }
  30. public static void main(String[] args) {
  31.  
  32. Scanner input = new Scanner(System.in);
  33. int n=Integer.parseInt(input.nextLine());
  34. float rads_degs1;
  35. String type1;
  36. List<String> list =new ArrayList();
  37. for (int i = 1;i<=n;i++)
  38. {
  39. rads_degs1=input.nextFloat();
  40. type1=input.next();
  41. list.add(radToDegreesAndOpp(rads_degs1,type1));
  42. }
  43. for (String i:list)
  44. {
  45. System.out.printf("%s%n",i);
  46. }
  47.  
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement