Java: Check if three given side lengths can make a triangle or not
Java Basic: Exercise-195 with Solution
Write a Java program to check if three given side lengths (integers) can make a triangle or not.
Pictorial Presentation:

Sample Solution:
Java Code:
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Input side1: ");
int s1 = in .nextInt();
System.out.print("Input side2: ");
int s2 = in .nextInt();
System.out.print("Input side3: ");
int s3 = in .nextInt();
System.out.print("Is the said sides form a triangle: " + isValidTriangle(s1, s2, s3));
}
public static boolean isValidTriangle(int a, int b, int c) {
return (a + b > c && b + c > a && c + a > b);
}
}
Sample Output:
Input side1: 5 Input side2: 6 Input side3: 8 Is the said sides form a triangle: true
Flowchart:

Java Code Editor:
Company: LinkedIn
Contribute your code and comments through Disqus.
Previous: Write a Java program to find the all positions of a given number in a given matrix. If the number not found print ("Number not found!").
Next: Write a Java program to create a spiral array of n * n sizes from a given integer n.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join