Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. public class Direction {
  2. public static void main(String[] args) {
  3. float[] degrees =
  4. {
  5. Math.nextAfter(337.5f, Double.NEGATIVE_INFINITY),
  6. 337.5f,
  7. Math.nextAfter(337.5f, Double.POSITIVE_INFINITY),
  8.  
  9. Math.nextAfter(22.5f, Double.NEGATIVE_INFINITY),
  10. 22.5f,
  11. Math.nextAfter(22.5f, Double.POSITIVE_INFINITY),
  12.  
  13. Math.nextAfter(67.5f, Double.NEGATIVE_INFINITY),
  14. 67.5f,
  15. Math.nextAfter(67.5f, Double.POSITIVE_INFINITY),
  16.  
  17. Math.nextAfter(112.5f, Double.NEGATIVE_INFINITY),
  18. 112.5f,
  19. Math.nextAfter(112.5f, Double.POSITIVE_INFINITY),
  20.  
  21. Math.nextAfter(157.5f, Double.NEGATIVE_INFINITY),
  22. 157.5f,
  23. Math.nextAfter(157.5f, Double.POSITIVE_INFINITY),
  24.  
  25. Math.nextAfter(202.5f, Double.NEGATIVE_INFINITY),
  26. 202.5f,
  27. Math.nextAfter(202.5f, Double.POSITIVE_INFINITY),
  28.  
  29. Math.nextAfter(247.5f, Double.NEGATIVE_INFINITY),
  30. 247.5f,
  31. Math.nextAfter(247.5f, Double.POSITIVE_INFINITY),
  32.  
  33. Math.nextAfter(292.5f, Double.NEGATIVE_INFINITY),
  34. 292.5f,
  35. Math.nextAfter(292.5f, Double.POSITIVE_INFINITY)
  36. };
  37.  
  38. for (float degree : degrees) {
  39. System.out.println(degree + " " + getWindDirection(degree));
  40. }
  41. }
  42.  
  43. private static String getWindDirection(float degrees) {
  44. // each direction is defined per 45 degrees, mod by 8 so that 360 = N
  45. // (may not be necessary depending on the data)
  46. String[] directions = new String[] {"N", "NE", "E", "SE", "S", "SW", "W", "NW"};
  47. return directions[(int) Math.round(degrees / 45) % 8];
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement