Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
check weather the sides are of right angled triangled or not
if input is a=10, b=20, c=15 then the output should be triangle:No

i have made the program, please tell me how the statement written by me is wrong

What I have tried:

class Main {
  public static void main(String[] args) {
     int a=10;
     int b=20;
     int c=15;
    
    if((a*a)+(b*b)=(c*c) || (b*b)+(c*c)=(a*a) || (c*c)+(a*a)=(b*b))
    {
      System.out.print("Triangle:Yes");
    }
    else
    {
      System.out.println("Triangle:No");
    }
  }
}
Posted
Updated 15-Mar-18 22:25pm

Go to The Java™ Tutorials[^] where you can study Java at your own pace, with excellent study materials.
 
Share this answer
 
Several issues.
The syntax issue:
= is assignment operator. You are looking for ==

The logic issue:
You are multiplying each variabl 3 times, you can improve that.
 
Share this answer
 
Comments
Member 13724614 15-Mar-18 19:00pm    
thank sir. but how can i improve the logic issue. can you give me the statement
Mohibur Rashid 16-Mar-18 0:45am    
one idea can be
class Main {
public static void main(String[] args) {
int a=10;
int b=20;
int c=15;
long aa = a*a;
long bb = b*b;
long cc = c*c;

if((aa + bb)==cc || bb+cc==aa || cc+aa==bb)
{
System.out.print("Triangle:Yes");
}
else
{
System.out.println("Triangle:No");
}
}
}


----------------------------------------
another can be

int arr[] = { a, b, c };
Arrays.sort(arr);
if ((arr[0] * arr[0] + arr[1] * arr[1]) == arr[2] * arr[2]) {
System.out.print("Triangle:Yes");
} else {
System.out.println("Triangle:No");
}
Member 13724614 16-Mar-18 15:55pm    
thanks a lot sir. I would request you to help in more programs as well if you could

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900