Given three sides of a triangle. Write the Program to
determine whether the triangle is :
1) Invalid
2) Right Angled
3) Isoscales
4) Equilateral
5) Not Special
An Isoscales right angled triangle should be taken as a
Right Angled Triangle
Answers were Sorted based on User's Feedback
Answer / sunil
if a, b and c are the three sides of a triangle, then a + b > c
if this is not satisfied, then its not a valid triangle.
To check for right angle, use Pythagoras theorem. Assume
that the longest side is the hypotenuse.
Issosless and Equilateral can be found by simply comparing
the sides.
| Is This Answer Correct ? | 65 Yes | 31 No |
Answer / giri
One should check for valid sides also. Side values dhould
be greated than ZERO.
Here is the correct routine:
public static String checkTriangle(int[]
triangleSide){
boolean validTriangle = false;
boolean validSides = true;
String result = "NOT VALID TRIANGLE";
for(int side: triangleSide)
if(side <= 0)
validSides = false;
if(validSides){
for(int count= 0; count< 3 ;
count++){
if(((triangleSide[count%3]
+ triangleSide[(count+1)%3]) > triangleSide[(count+2)%3]))
validTriangle =
true;
}
if(validTriangle){
if( triangleSide[0] ==
triangleSide[1] && triangleSide[2] == triangleSide[1])
result
= "EQUILATERAL";
else{
for(int count= 0;
count< 3 ; count++){
if( (
triangleSide[count%3] * triangleSide[count%3] + triangleSide
[(count+1)%3] * triangleSide[(count+1)%3]) == (triangleSide
[(count+2)%3] * triangleSide[(count+2)%3])){
result = "RIGHANGLED";
break;
}else
if
((triangleSide[count%3] == triangleSide[(count+1)%3]))
result = "ISOSCALAUS";
}
}
if("NOT VALID
TRIANGLE".equals(result))
result = "NOT
SPECIAL";
}
}
System.out.println(result);
return result;
}
| Is This Answer Correct ? | 32 Yes | 29 No |
Answer / ganesh bhat
I believe, this is more efficient one. solves all the cases.. comments please. Written in java
public static Map validateTriange(int a,int b,int c)
{
Map props = new HashMap();
boolean isValidTriangle;
int bigSide = a;
if(bigSide<b){bigSide = b;}
if(bigSide<c){bigSide = c;}
boolean isSpecial = false;
if((a+b+c-bigSide)>bigSide)
{
props.put("VALID","YES");
}
else
{
props.put("VALID","NO");
return props;
}
if(a == b||b==c||c == a)
{
props.put("ISOSCELES","YES");
isSpecial = true;
}
if(a == b && b == c)
{
props.put("EQUALATERAL","YES");
isSpecial = true;
}
if(((a*a+b*b+c*c)-bigSide*bigSide) == bigSide*bigSide)
{
props.put("RIGHT_ANGLED","YES");
isSpecial = true;
}
return props;
}
| Is This Answer Correct ? | 22 Yes | 22 No |
For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?
In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..
which property is used to display the advertisements with adrotator control
how to check single or double byte in struts
plz send me NIC Scientific Officer /Engineer-SB(Programmer) previous question paper or syllabus
What is the difference between COM and CORBA?
what is the difference between Windows application and Unix application?
how do find the user exit for selected feild whatis the process and can u plz explain it
in cobol,wat is the difference in using 'set index in occurs clause' ....and 'occurs depending-on clause'
What is the meaning of client-server application. The purpose of Client-Server Application. with description.
What is the language used for Artificial Intelligence?
hi..this is kartheek..complted mca in 2009..but i dont have knowledge in programing..but to learn new language.. which one is suitable for me?is SAP or IBM mainframes is suitable for me..?if it suits how much will it costs..?pls answer...