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
Explain what is OOPS and its concepts?
Write a shell program. Enter number of days from keyboard. Find out the number of years, month and days it contains
smal talk is pure object oriented or not?
in network security,how we identified threat?some one say we found threat according to it's signature,but how we get signature or pattern of the virus?
Code for display the images from drive using vb 6.0?
what is delimiter in sas ?
1.what is the vesition managment.
Write a program to find whether a given number is prime or not.
Hello...has anyone interviewed with Information Management Services(IMS)located in Silver Spring MD??If yes,what can you share about the programming test and the analytical test?
Write a program to reverse a number?
I need source code for Enrollment System using Visual Basic 6.0/2008 database MS Access 2007 for my school thesis project...please help me..kindly send in my email jpinedamcp@gmail.com
Define Form modules, Class modules and Standard modules
what is the similarity between networking devices?
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
8.In DSP,Define Signal and System?and various type of signals.