vendredi 25 septembre 2020

Why is my Java Code Using an If else Statement to determine if a triangle is right not working?

The following code is to determine if a triangle is right. The if else statement compares three variables: x, y, and z. For some reason Java isn't properly using the if else statement. When I entered 3,4,5 for the values it returned not a right triangle.

    System.out.println("On to the Pythagorean Theorem!");
System.out.println("Please enter a double");
double x = scan.nextDouble();
System.out.println("Please enter another double");
double y = scan.nextDouble();
System.out.println("Please enter another double");
double z = scan.nextDouble();

System.out.println("You entered: " + x + ", " + y + ", and " + z);

if(x > y && x > z)
{
  if(((Math.pow(z,2)) + (Math.pow(y,2))) = Math.sqrt(x))
  {
    System.out.println("This is a right triangle!");
  }
  else
  {
    System.out.println("This isn't a right triangle.");
  }
}
if(y > x && y > z)
{
  if(((Math.pow(x,2)) + (Math.pow(z,2))) = Math.sqrt(y)) 
  {
    System.out.println("This is a right triangle!");
  }
  else
  {
    System.out.println("This isn't a right triangle.");
  }
}
if(z > x && z > y)
{
  if(((Math.pow(x,2)) + (Math.pow(y,2))) = Math.sqrt(z))
  {
    System.out.println("This is a right triangle!");
  }
  else
  {
    System.out.println("This isn't a right triangle.");
  }
}

Aucun commentaire:

Enregistrer un commentaire