Computer Science, asked by Anonymous, 6 months ago

Write a program to test whether 3 given sides form a triangle or not use scanner class java/python programming

Answers

Answered by shinchen08
4

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);

}

}

Answered by Itzraisingstar
8

Question:

Write a program to test whether 3 given sides form a triangle or not use scanner class java/python programming.

\bold{Answer:}

import java . util. Scanner;

public Triangle Test

{

  public static boolean Can make(ints1,intsd2,ints3)

   {

       boolean result;

       if(s1+s2>s3&& s2+s3>s1&&s3+s1>s2)

            result=true;

       else

            result=false;

       return result;

   }

   public static void main(String[]args)

   {

      Scanner sc= new Scanner(system.in);

      int side1.side2,side3;

      System.out.println("Enter 3 sides");

      side1=sc.nextInt();

      side2=sc.nextInt();    

      side3=sc.nextInt();

      if(CanMake(side1,side2.side3)==true)

            System.out.println("Given 3 sides will make a triangle");

      else

            System.out.println("Given 3 sides CANNOT make a triangle");

    }

}

Output:

Enter 3 sides

10 14 12

Given 3 sides will make a triangle

Enter 3 sides

10 4 3

Given 3 sides CANNOT make a triangle.

Similar questions