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 |
the channel in the data communication model can be? option a.postal mail serv. b telephon lines c.radio signals d. all the above
2 Answers iNautix, National Investment Commission,
This is the portal and portlet interview question API: is JSR 168 API Server: is ibm web sphere portal server6.0 IDE: is RAD 7.0 Question:In normal struts what is the actionservlet? Ans:org.apache.struts.action.ActionServlet. But What is the actionservlet in strutsportlet?
what is the diffrence between occur 0 and occur 10 in ABAP.
What do you understand by modular programming?
where is available in this mantis toturials?
what is the difference between an OS(operating system) and Framework?
smal talk is pure object oriented or not?
which is the best institute for testing tools in hyderabad?
how to study PHP my own? i reffered many sites.. but as being a fresher i couldnt follow those... which site will be the best one?
Hello all, My name is Nrupali, am a fresher, i know C language beginner. dont have any experience. planning to learn Php. let me know which language should i choose to learn or for salary purpose and growth??? kindly help me to take decision. thanks
What is meant by spooling
Is there any standard procedure to test the application as a whole? Or How can I test complete application right from the requirement gathering?