Advertisement
advictoriam

Untitled

Nov 28th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that reads in an angle of any size (positive or negative),
  5.    normalizes it, and prints it out.
  6.    For example, the input of 380 should print 20,
  7.    and the input of -30 should return 330.
  8.    All variables should be of type int.
  9. */
  10. public class Angles
  11. {
  12.    public static void main (String[] args)
  13.    {
  14.       // Display prompt for degrees of angle
  15.       System.out.println("Please enter the number of degrees of angle: ");
  16.  
  17.       // Read angle in degrees
  18.       Scanner in = new Scanner(System.in);
  19.       int angle = in.nextInt();
  20.      
  21.       // Compute normalized value of angle
  22.       int normalized = angle;
  23.       while(normalized < 0 || normalized > 359)
  24.       {
  25.          if(normalized < 0)
  26.          {
  27.             normalized += 360;
  28.          }
  29.          else
  30.          {
  31.             normalized -= 360;
  32.          }
  33.       }
  34.  
  35.       // Print out the normalized value of the angle
  36.       System.out.println(normalized);
  37.    }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement