Q:

Write a Java program to check if three given side lengths (integers) can make a triangle or not

0

Write a Java program to check if three given side lengths (integers) can make a triangle or not

Expected Output:

Input side1:  5
Input side2:  6
Input side3:  8
Is the said sides form a triangle: true 

All Answers

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

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 

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