Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- A program that reads in an angle between 0 and 359,
- and prints out which quadrant it is in.
- For example, the input of 20 is in quadrant I, and
- similarly, the input of 330 is in quadrant IV.
- Use error validation to print out an error message
- if an input angle is not between 0 and 359 degrees.
- */
- public class Quadrants
- {
- public static void main (String[] args)
- {
- // Display prompt for degrees of angle
- System.out.println("Please enter the number of degrees of angle: ");
- // Read angle in degrees
- Scanner in = new Scanner(System.in);
- int angle = in.nextInt();
- String quadrant;
- // Determine and print out the quadrant for the angle as "I", "II", "III", or
- // "IV", or print the word "Error"
- if(angle >= 360){quadrant = "error";}
- else if(angle >= 270){quadrant = "IV";}
- else if(angle >= 180){quadrant = "III";}
- else if(angle >= 90){quadrant = "II";}
- else if(angle >= 0){quadrant = "I";}
- else{quadrant = "error";}
- System.out.println(quadrant);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement