KnowledgeBoat Logo
|

Computer Applications

Write a program to accept three angles of a triangle and check whether the triangle is possible or not and display the message accordingly.

Java

Input in Java

22 Likes

Answer

import java.io.*;

public class KboatTriangle
{
    public static void main(String args[]) throws IOException {
        InputStreamReader read = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(read);
        
        System.out.print("Enter first angle: ");
        int a = Integer.parseInt(in.readLine());
        
        System.out.print("Enter second angle: ");
        int b = Integer.parseInt(in.readLine());
        
        System.out.print("Enter third angle: ");
        int c = Integer.parseInt(in.readLine());
        
        int sum = a + b + c;
        
        if(a != 0 && b != 0 && c != 0 && sum == 180) {
            if((a + b) >= c || (b + c) >= a || (a + c) >= b) {
                System.out.println("Triangle is possible");
            }
            else {
                System.out.println("Triangle is not possible");
            }
        }
        else {
            System.out.println("Triangle is not possible");
        }
    }
}

Output

BlueJ output of Write a program to accept three angles of a triangle and check whether the triangle is possible or not and display the message accordingly.BlueJ output of Write a program to accept three angles of a triangle and check whether the triangle is possible or not and display the message accordingly.

Answered By

9 Likes


Related Questions