答案://@Author wangfeng
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class area {
static InputStreamReader in;
static BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
public static boolean judge(int a,int b,int c)
{
int[] array = new int[3];
array[0] = a;
array[1] = b;
array[2] = c;
for (int i = 0;i < 2; i ++)
{
for (int j = 0; j <2 - i; j++)
if(array[j] > array[j +1])
{
int temp = array[j];
array[j] = array[j + 1];
array[j + 1]= temp;
}
}
if((array[0] + array[1]) > array[2])
{
System.out.println("你输入的三条边能构成三角形");
return true;
}
else
{
System.out.println("你输入的三条边不能构成三角形");
return false;
}
}
public static void calculate()
{
int array[] = new int [3];
double answer = 0.0;
int p = 0;
try{
for (int i = 0;i < 3; i ++)
{
System.out.println("请输入第" + (i+1) +"条边");
array[i] = Integer.parseInt(breader.readLine());
}
}catch(Exception e){};
if(judge(array[0],array[1],array[2] ) == true)
{
p = (array[0]+ array[1]+array[2])/2;
answer = Math.sqrt(p * (p - array[0]) * (p - array[1]) * (p - array[2]));
System.out.println( "你输入的三条边构成的三角形面积为:" + answer);
}
}
public static void main(String [] argu)
{
calculate();
}
}
上一个:在java编程中,SE是设计人员,那么PG是干什么的呢?
下一个:java微信怎么下