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 IBM PC -AT.WAT AT REFERS TO?

0 Answers   IBM,


what are the differences between CONS, LIST, and APPEND

0 Answers   Comtech,


In Bioinformatics, a DNA sequence is made up of a combination of 4 characters, namely “A,C,G,T”. A subsequence of a given sequence of characters a0, a1, …an- 1, is any subset of the characters taken in order, of the form ai0 , ai1 ,…..aik-1 where 0 &#8804; i0 <i1….< ik-1 &#8804; n-1. For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, we can have subsequences “A,G,T”, “A,C,A,A” and many more. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many palindromic subsequences, including “A,C,G,C,A” and “A,A,A,A” (on the other hand, the subsequence “A,C,T” is not palindromic). Devise an algorithm (using dynamic programming) that takes a sequence of characters X[0 … n-1] from the alphabet set (A,C,G,T) and returns the (length of the) longest palindromic subsequence. Implement the algorithm in an appropriate language.

1 Answers  


Need provab technical test questions

0 Answers  


WS-NUM PIC S9(05)V(02) SIGN TRAILING SEPARATE MOVE '0050000+' TO WS-NUM The value stored is 00500,00+ MOVE '0050000-' TO WS-NUM Then what is the value will be stored in WS-NUM? Am getting '-00500,00'.....>>> What should I declare to WS-NUM so that I can get correct values for both + & - signs.

0 Answers  






in a VB application, where the data will be stored after manipulation? what is the syntax for that?

0 Answers   TCS,


It is possible to take number of controls added to form at run-time.ex-when user enter 6, 6 text boxes get added to form,next time number of controls get change as per user number enter. What is code for that?

0 Answers   Honeywell,


What sysoption determines where the macro facility searches a specific catalog for complied macro?

0 Answers   GE,


Given: coordinates of rectangle-> left bottom and right top points. the rectangles create a hole.Find the maximum area of the hole. eg. 4 rectangles create a hole in between. find its area.

0 Answers   Manhattan,


how can i apply validation without using errorprovider in C# windows application

1 Answers  


hi this is uday i want prepare for nic exam if any one have previous question papers please send me or atlest guide me how to prepare my ID is udaykiran4u@in.com

0 Answers  


Can anyone send me NIC question papers alongwith answers on nidhi1485@yahoo.co.in? Urgently needed.. Thanks in advance

0 Answers  


Categories