Q:

Write a Java program to check whether three given lengths (integers) of three sides form a right triangle

0

Write a Java program to check whether three given lengths (integers) of three sides form a right triangle. Print "Yes" if the given sides form a right triangle otherwise print "No"

Input:

Each test case consists of two non-negative integers a and b which are separated by a space in a line. 0 ≤ a, b ≤ 1,000,000

Expected Output:

Input three integers(sides of a triangle)
 6 9 12
If the given sides form a right triangle?
No

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner; 
class Main {
    Scanner sc = new Scanner(System.in);
    public void run() {
		System.out.println("Input three integers(sides of a triangle)");
        int[] int_num = new int[]{
               sc.nextInt(),sc.nextInt(),sc.nextInt()
            };
            Arrays.sort(int_num);
			System.out.println("If the given sides form a right triangle?"); 
            ln((int_num[2]*int_num[2]==int_num[0]*int_num[0]+int_num[1]*int_num[1])?"Yes":"No");        
    } 
    public static void main(String[] args) {
        new Main().run();
    } 
    public static void pr(Object o) {
        System.out.print(o);
    } 
    public static void ln(Object o) {
        System.out.println(o);
    } 
    public static void ln() {
        System.out.println();
    }
}

Sample Output:

Input three integers(sides of a triangle)
 6 9 12
If the given sides form a right triangle?
No

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now