Hello.
I have to write a program to read 3 values to check if they can form a triangle (any side is not larger the the other 2 sides combined).
So I wote:
import java.util.Scanner;
public class Triangle
{
//-----------------------------------------------------------------------------------------------------------
// Calculates total length of sides of a triangle and determines triangle type. Prints an error if a triangle
// cannot be formed.
//-----------------------------------------------------------------------------------------------------------
public static void main (String []args)
{
Scanner scan = new Scanner(System.in);
double side1, side2, side3;
System.out.println ("Please enter 3 numbers representing the length of each side of the triangle to be formed");
side1 = scan.nextDouble();
side2 = scan.nextDouble();
side3 = scan.nextDouble();
if (side1 > side2 + side3) //
if (side2 > side1 + side3) // Determines whether a triangle can be formed by the 3 values
if (side3 > side1 + side2)
System.out.println ("temp messgae ...error");
else
System.out.println ("ok");
But it won`t print, how can I combine the IFs. I have to use those also to define the triangle type (quilateral, isosceles or scalene).
Thanks for any help.
I have to write a program to read 3 values to check if they can form a triangle (any side is not larger the the other 2 sides combined).
So I wote:
import java.util.Scanner;
public class Triangle
{
//-----------------------------------------------------------------------------------------------------------
// Calculates total length of sides of a triangle and determines triangle type. Prints an error if a triangle
// cannot be formed.
//-----------------------------------------------------------------------------------------------------------
public static void main (String []args)
{
Scanner scan = new Scanner(System.in);
double side1, side2, side3;
System.out.println ("Please enter 3 numbers representing the length of each side of the triangle to be formed");
side1 = scan.nextDouble();
side2 = scan.nextDouble();
side3 = scan.nextDouble();
if (side1 > side2 + side3) //
if (side2 > side1 + side3) // Determines whether a triangle can be formed by the 3 values
if (side3 > side1 + side2)
System.out.println ("temp messgae ...error");
else
System.out.println ("ok");
But it won`t print, how can I combine the IFs. I have to use those also to define the triangle type (quilateral, isosceles or scalene).
Thanks for any help.