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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of sas software? Is sas and sap are different?

1017


When we use Windows authentication mode

1580


When will you use shell script/Perl ahead of C/C++?

657


purpose of abstraction and interface

1528


How to use string functions in QTP?give some examples

7119






in cobol,wat is the difference in using 'set index in occurs clause' ....and 'occurs depending-on clause'

1774


What r the attributes using in Win Runner?

1948


details description on this mantis? who is founder of this mantis?

1681


sample code for data transfer between two r/2 systems and r/3 systems?

1493


ok how would i do the following extract from a file i have ssns = 267907230 which are in column 7 into a separate data set then create a 2nd job step to extract from the data set created the following "fund code" which is in column 31 and is 113 into yet another data set

1561


could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?

1293


How will you prove that java swing is multithreaded?

1698


hi i m deepak my shedule for NIC pi is 17 Apr please contact me if anybody has interview on same day or give me some idea who have faced

1561


through which algorithm does the garbage collector works? how the garbage collector will understand that the object will going to be deleted?

2073


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 ?

3214