Write a java program to by considering three positive integers a,b and c determine whether they can form three sides of a triangle yes determine whether triangle is right angle or obtuse or acute. Display the message accordingly.
import java.lang.Math;
class RightTriangle
{
public static void main(String args[])
{
int side1,side2,angle;
side1=Integer.parseInt(args[0]);
side2=Integer.parseInt(args[1]);
angle=Integer.parseInt(args[2]);
if((side1>0 && side2>0)&&(angle >0 && angle<=180))
{
System.out.println("Valid Triangle");
}
else
{
System.out.println("Not Valid Triangle");
System.out.println("Now we end the program...");
System.exit(0);
} if((side1>0 && side2>0)&&(angle>0 && angle==90))
{
System.out.println("Right angle Triangle");
}
if((side1>0 && side2>0)&&(angle>0 && angle<90))
{
System.out.println("Acute Triangle");
}
if((side1>0 && side2>0)&&(angle>90 && angle<180))
{
System.out.println("Obtuse Triangle");
} }
}
output:
D:\JavaPrograms\CmdPrograms>javac RightTriangle.java
D:\JavaPrograms\CmdPrograms>java RightTriangle 10 12 90
Valid Triangle
Right angle Triangle
D:\JavaPrograms\CmdPrograms>java RightTriangle 10 20 60
Valid Triangle
Acute Triangle
D:\JavaPrograms\CmdPrograms>java RightTriangle 10 5 160
Valid Triangle
Obtuse Triangle
0 Comments
Post a Comment