Advertisement
advictoriam

Untitled

Dec 7th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    A program that reads in an angle between 0 and 359,
  5.       and prints out which quadrant it is in.
  6.    For example, the input of 20 is in quadrant I, and
  7.       similarly, the input of 330 is in quadrant IV.
  8.    Use error validation to print out an error message
  9.       if an input angle is not between 0 and 359 degrees.
  10. */
  11. public class Quadrants
  12. {
  13.    public static void main (String[] args)
  14.    {
  15.       // Display prompt for degrees of angle
  16.       System.out.println("Please enter the number of degrees of angle: ");
  17.  
  18.       // Read angle in degrees
  19.       Scanner in = new Scanner(System.in);
  20.       int angle = in.nextInt();
  21.  
  22.       String quadrant;
  23.  
  24.       // Determine and print out the quadrant for the angle as "I", "II", "III", or
  25.       // "IV", or print the word "Error"
  26.       if(angle >= 360){quadrant = "error";}
  27.       else if(angle >= 270){quadrant = "IV";}
  28.       else if(angle >= 180){quadrant = "III";}
  29.       else if(angle >= 90){quadrant = "II";}
  30.       else if(angle >= 0){quadrant = "I";}
  31.       else{quadrant = "error";}
  32.      
  33.  
  34.       System.out.println(quadrant);
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement