Homework 1: Triangle Angles

← Back to assignments

Logic & Computation · Homework

Triangle Angles

Practice variables and conditionals by checking the three angles of a triangle.

Homework 1 · double variables · conditionals

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.

Given angles and expected output
Angle 1Angle 2Angle 3Expected output
606060The triangle is valid.
505050The 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

Submit your completed Homework1.java file to [email protected].