Logic & Computation · Homework
Triangle Angles
Practice variables and conditionals by checking the three angles of a triangle.
Your task
Write a program that checks the given three angles of a triangle, and returns whether the triangle angles are valid, or not.
The triangle angles can also be decimal numbers, so please use the variable type double.
Output: Print The triangle is valid. or The triangle is invalid., depending on the given angles.
Example cases
Use these original example cases to check your program.
| Angle 1 | Angle 2 | Angle 3 | Expected output |
|---|---|---|---|
| 60 | 60 | 60 | The triangle is valid. |
| 50 | 50 | 50 | The triangle is invalid. |
Check: Run your program with both sets of angles. The message should change because your program checks the values, rather than because you edited the output statement.
Starter code
Create a file named Homework1.java. The filename must match public class Homework1. Fill in your name and date, then write your solution inside main.
/*
* Name:
* Project: Homework 1 - Triangle Angles
* Date:
*/
public class Homework1 {
public static void main(String args[]) {
// START: Write your solution below this line.
// TODO: Store the three angles using double variables.
// TODO: Check whether the triangle angles are valid.
// TODO: Print whether the triangle is valid or invalid.
// END: Keep the closing braces below.
}
}
Before submitting
- Fill in your name and date.
- Use
doublevariables for the three angles. - Make your program decide whether the triangle is valid or invalid.
- Run both example cases and check the output.
- Save your completed file as
Homework1.java.
Submit your completed Homework1.java file to [email protected].