# Java: Check whether three given lengths of three sides form a right triangle

## Java Basic: Exercise-213 with Solution

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:

Integers separated by a single space. 1 ≤ length of the side ≤ 1,000

Pictorial Presentation:  Sample Solution:

Java Code:

``````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*int_num==int_num*int_num+int_num*int_num)?"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
```

Flowchart: Java Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿

## Java: Tips of the Day

Java Classes

A Java class is declared with the keywords public class along with a unique class name mirroring its file name. For example, in a file Hello.java in project helloworld:

```package helloworld;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
* @author seth
* A GUI hello world.
*/

public class Hello {
// this is an empty class
}
```

You can declare variables and functions inside a class. In Java, variables within a class are called fields.

Ref: https://red.ht/3sL3sSl

We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook