题目
在java中从键盘输入三角形的三边长,判断是否构成三角形,若能,则计算三角形的面
提问时间:2020-08-09
答案
//@Author wangfeng
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class area {
x05static InputStreamReader in;
x05static BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
x05public static boolean judge(int a,int b,int c)
x05{
x05x05int[] array = new int[3];
x05x05array[0] = a;
x05x05array[1] = b;
x05x05array[2] = c;
x05x05
x05x05for (int i = 0;i < 2; i ++)
x05x05{
x05x05x05for (int j = 0; j array[j +1])
x05x05x05x05{
x05x05x05x05x05int temp = array[j];
x05x05x05x05x05array[j] = array[j + 1];
x05x05x05x05x05array[j + 1]= temp;
x05x05x05x05}
x05x05x05
x05x05}x05
x05x05
x05x05if((array[0] + array[1]) > array[2])
x05x05x05
x05x05x05{
x05x05x05System.out.println("你输入的三条边能构成三角形");
x05x05x05return true;
x05x05x05}
x05x05
x05x05else
x05x05x05{
x05x05x05 System.out.println("你输入的三条边不能构成三角形");
x05x05x05 return false;
x05x05x05}
x05}
public static void calculate()
{
x05int array[] = new int [3];
x05double answer = 0.0;
x05int p = 0;
x05try{
x05for (int i = 0;i < 3; i ++)
x05x05{
x05x05x05System.out.println("请输入第" + (i+1) +"条边");
x05x05x05array[i] = Integer.parseInt(breader.readLine());
x05x05}
x05}catch(Exception e){};
x05
x05if(judge(array[0],array[1],array[2] ) == true)
x05{
x05x05p = (array[0]+ array[1]+array[2])/2;
x05 answer = Math.sqrt(p * (p - array[0]) * (p - array[1]) * (p - array[2]));
x05System.out.println( "你输入的三条边构成的三角形面积为:" + answer);
x05}
}
public static void main(String [] argu)
{
x05calculate();
x05
}
}
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class area {
x05static InputStreamReader in;
x05static BufferedReader breader = new BufferedReader(new InputStreamReader(System.in));
x05public static boolean judge(int a,int b,int c)
x05{
x05x05int[] array = new int[3];
x05x05array[0] = a;
x05x05array[1] = b;
x05x05array[2] = c;
x05x05
x05x05for (int i = 0;i < 2; i ++)
x05x05{
x05x05x05for (int j = 0; j array[j +1])
x05x05x05x05{
x05x05x05x05x05int temp = array[j];
x05x05x05x05x05array[j] = array[j + 1];
x05x05x05x05x05array[j + 1]= temp;
x05x05x05x05}
x05x05x05
x05x05}x05
x05x05
x05x05if((array[0] + array[1]) > array[2])
x05x05x05
x05x05x05{
x05x05x05System.out.println("你输入的三条边能构成三角形");
x05x05x05return true;
x05x05x05}
x05x05
x05x05else
x05x05x05{
x05x05x05 System.out.println("你输入的三条边不能构成三角形");
x05x05x05 return false;
x05x05x05}
x05}
public static void calculate()
{
x05int array[] = new int [3];
x05double answer = 0.0;
x05int p = 0;
x05try{
x05for (int i = 0;i < 3; i ++)
x05x05{
x05x05x05System.out.println("请输入第" + (i+1) +"条边");
x05x05x05array[i] = Integer.parseInt(breader.readLine());
x05x05}
x05}catch(Exception e){};
x05
x05if(judge(array[0],array[1],array[2] ) == true)
x05{
x05x05p = (array[0]+ array[1]+array[2])/2;
x05 answer = Math.sqrt(p * (p - array[0]) * (p - array[1]) * (p - array[2]));
x05System.out.println( "你输入的三条边构成的三角形面积为:" + answer);
x05}
}
public static void main(String [] argu)
{
x05calculate();
x05
}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
热门考点