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

In java without use of main() how to execute the program

0 Answers  


what is inprocess and outprocess in vb

1 Answers   Msoft,


When we delete logfiles such as screenshots how does it affect the ldf file? Ive seen huge change while adding screenshots in the ldf file but a very minor one deleting them.Please Explain

0 Answers  


what is the filters in biztakk server? where it can use?

0 Answers   Wipro,


cobol is execution r not without jcl

0 Answers   IBM,






Write a Pseudo Code to fins the LCM of two given numbers

5 Answers   Goldman Sachs,


When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)

0 Answers   Yahoo,


Write a program to find whether a given number is prime or not.

0 Answers   Syntel, Visa,


what are the missinschema properties and should we pass primary key in select command

0 Answers  


List and explain any five built in functions for Lists data type in python

1 Answers   Peerless,


How do you pass variables forwrd to future CECI sessions

0 Answers   Mind Tree,


Write a pascal program to calculate the sum of the first 100 even number and odd number

0 Answers  


Categories