三角形判断

某人刚学Java,一道三角形判断题,下面是代码。记录在此,以资鼓励!

输入a,b,c,如果这三个数满足三角形的条件,则计算三角形的周长,否则输出提示错误。然后判断三角形是等腰三角形还是等边三角形,若是等腰三角形则打印输出等腰三角形,若是等边三角形则打印输出等边三角形,否则退出。请给出程序流程及控制流程,测试路径。试举一个测试用例.
import java.io.*;
class Triangle
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br1.readLine());
		BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
		int b=Integer.parseInt(br2.readLine());
		BufferedReader br3=new BufferedReader(new InputStreamReader(System.in));
		int c=Integer.parseInt(br3.readLine());
		Triangle tri=new Triangle();
		IsTriangle ist=new IsTriangle(a,b,c);
		IsoscelesTriangle iso=new IsoscelesTriangle(a,b,c);
	}
	
}

class IsTriangle
{
	private int a;
	private int b;
	private int c;
	IsTriangle(int a,int b,int c)
	{
		this.a=a;
		this.b=b;
		this.c=c;
	    	if(a>0&&b>0&&c>0)    	
	      {
	    	if((a+b)>c&&(a+c)>b&&(b+c)>a)
	    	 {
	    		System.out.printf("This is a Triangle and the primeter is"+(a+b+c));
	    	 }
	    	else
	    	 {
	    		System.out.printf("This is not a Triangle for the sum of any two sides is not greater than the third side.");
	    		//return Error;
	    	 }
	      }
	    else
	     {
	    	System.out.printf("This is not a Triangle for the value of some side is not a positive number.");
	    	//return Error;
	     }
	}	 
} 
 
class IsoscelesTriangle
{
	private int a;
	private int b;
	private int c;
	IsoscelesTriangle(int a,int b,int c)
	{
		this.a=a;
		this.b=b;
		this.c=c;
		if(a==b)                                           
	  {
	  	if(b==c)
	  	{
	  		System.out.printf("This is EquilateralTriangle.");
	  	}
	  	else
	  	{
	  		System.out.printf("This is IsoscelesTriangle.");
	  		return;
	  	}                                                 	  	                                 
	  }
	  else
	  {
	  	if(a==c)
	  	{
	  		System.out.printf("This is IsoscelesTriangle.");
	  	}
	  	else
	  	{
	  		if(b==c)
	  		{
	  			System.out.printf("This is IsoscelesTriangle.");
	  		}
	  		else
	  		{
	  			System.out.printf("This is CommonTriangle.");
	  			return;
	  		}
	  		return;
	  	}
	  	return;
	  } 
	}                                               
}

你可能感兴趣的:(C++,c,面试,C#)