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
What is the use of sas software? Is sas and sap are different?
When we use Windows authentication mode
When will you use shell script/Perl ahead of C/C++?
purpose of abstraction and interface
How to use string functions in QTP?give some examples
in cobol,wat is the difference in using 'set index in occurs clause' ....and 'occurs depending-on clause'
What r the attributes using in Win Runner?
details description on this mantis? who is founder of this mantis?
sample code for data transfer between two r/2 systems and r/3 systems?
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
could you please tell me how to draw the calibration curve for HPLC {the software which we are using}?
How will you prove that java swing is multithreaded?
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
through which algorithm does the garbage collector works? how the garbage collector will understand that the object will going to be deleted?
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 ?