A. 求代码 使用java命令行参数方式,从键盘输入梯形的上底、下底和高,编程计算该梯形的面积。
publicstaticvoidmain(String[]args){
try{
doubletop=Double.valueOf(args[0]);
doublebottom=Double.valueOf(args[1]);
doubleheight=Double.valueOf(args[2]);
doublearea=(top+bottom)*height/2;
System.out.println("梯形面积是:"+area);
}catch(Exceptione){
System.out.println("命令行参数错误");
}
}
javac xxx.java
java xxx 2 4 5
B. java编写梯形面积
class Tixing //梯形类{ private float Height; //高 private float upBotton;//上底 private float downBotton;//下底 public Tixing(float Height,float upBotton,float downBotton)//构造方法 { this.Height=Height; this.upBotton=upBotton; this.downBotton=downBotton; } public float getTixingArea() //计算梯形面积 { return (upBotton+downBotton)*height/2; }}public class Start{ public static void main(String[] args) { Tixing t=new Tixing(30,20,50);//构造 System.out.println("梯形的面积是:"+t.getTixingArea());//打印输出 }}C. 跪求 JAVA计算梯形面积代码
import java.util.Scanner;
public class Sum{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入上底长度");
int a=sc.nextInt();
System.out.println("请输入下底长度");
int b=sc.nextInt();
System.out.println("请输入高");
System.out.println("梯形面积为"+((a+b)*sc.nextInt()));
}
}