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



Given three sides of a triangle. Write the Program to determine whether the triangle is : 1) Inval..

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

Given three sides of a triangle. Write the Program to determine whether the triangle is : 1) Inval..

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

Given three sides of a triangle. Write the Program to determine whether the triangle is : 1) Inval..

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

Post New Answer

More Programming Languages AllOther Interview Questions

Data Structure: Show that if k is the smallest integer greater than or equal to n+ (log2n)-2, k comparisons are necessary and sufficient to find the largest and second largest elements of a set of n distinct elements. (k comparisons are required to find what you are looking for, but no more than that are needed)

0 Answers   Student,


19. Given a system that is described with the following equation, X=A+(B.(A̅+C)+C)+A.B.(D̅+E̅) a) Simplify the equation using Boolean Algebra. b) Implement the original and then the simplified equation with a digital circuit. c) Implement the original and then the simplified equation in ladder logic.

0 Answers   Bajak Paint,


I am looking for selenium RC online Training in chennai. can any one tell me the best institute

0 Answers  


what is the work of 1tier,2tier,&ntier? Plz Explain it!

0 Answers  


What are the Advantages of HashMap over Vector?

1 Answers  






can u help me? how do solve the transpose problem in ireport? if any one know send to eswaran_2006@yahoo.co.in

0 Answers  


Suppose i have all the implementation code required is written in doGet() but my class has doPost() method. i need code implemented in doGet() how can we do that?

1 Answers  


A string of charaters were given. Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE

7 Answers   Nagarro,


What is the output of the following x = "abcdef" i = "a" for i in x: print(i), a) no output b) i i i i i i … c) a a a a a a … d) a b c d e f

0 Answers   Peerless,


why we use static with only main()class not with other class

2 Answers   TCS,


1. Write a program to create a sentence at runtime and count number of vowels in it ? 2. Write a program to get a string and to convert the 1st letter of it to uppercase ?

0 Answers   HTC,


how to convert infix expression to prefix expression?

0 Answers   nvidia,


Categories