Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Direction {
- public static void main(String[] args) {
- float[] degrees =
- {
- Math.nextAfter(337.5f, Double.NEGATIVE_INFINITY),
- 337.5f,
- Math.nextAfter(337.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(22.5f, Double.NEGATIVE_INFINITY),
- 22.5f,
- Math.nextAfter(22.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(67.5f, Double.NEGATIVE_INFINITY),
- 67.5f,
- Math.nextAfter(67.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(112.5f, Double.NEGATIVE_INFINITY),
- 112.5f,
- Math.nextAfter(112.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(157.5f, Double.NEGATIVE_INFINITY),
- 157.5f,
- Math.nextAfter(157.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(202.5f, Double.NEGATIVE_INFINITY),
- 202.5f,
- Math.nextAfter(202.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(247.5f, Double.NEGATIVE_INFINITY),
- 247.5f,
- Math.nextAfter(247.5f, Double.POSITIVE_INFINITY),
- Math.nextAfter(292.5f, Double.NEGATIVE_INFINITY),
- 292.5f,
- Math.nextAfter(292.5f, Double.POSITIVE_INFINITY)
- };
- for (float degree : degrees) {
- System.out.println(degree + " " + getWindDirection(degree));
- }
- }
- private static String getWindDirection(float degrees) {
- // each direction is defined per 45 degrees, mod by 8 so that 360 = N
- // (may not be necessary depending on the data)
- String[] directions = new String[] {"N", "NE", "E", "SE", "S", "SW", "W", "NW"};
- return directions[(int) Math.round(degrees / 45) % 8];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement