「java写梯形」梯形面积编程怎么写

博主:adminadmin 2022-11-24 01:52:06 65

本篇文章给大家谈谈java写梯形,以及梯形面积编程怎么写对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

求代码 使用Java命令行参数方式,从键盘输入梯形的上底、下底和高,编程计算该梯形的面积。

public static void main(String[] args) {

    try {

        double top = Double.valueOf(args[0]);

        double bottom = Double.valueOf(args[1]);

        double height = Double.valueOf(args[2]);

        double area = (top + bottom) * height / 2;

        System.out.println("梯形面积是:" + area);

    } catch (Exception e) {

        System.out.println("命令行参数错误");

    }

}

javac xxx.java

java xxx 2 4 5

Java写一个打印梯形的类,里面有上底、下底、高之类的参数和一个打印梯形的方法,然后自己在函数里面调用

static class Tixing {

    public int side1,side2,height;

    public Tixing(int side1, int side2, int height){

        this.side1 = side1;

        this.side2 = side2;

        this.height = height;

    }

}

public static void printTixing(Tixing tx){

    System.out.println("该梯形的上底为:"+tx.side1+",下底为:"+tx.side2+",高为:"+tx.height+",面积为:"+(int)((tx.side1+tx.side2)*height/2.0));

}

public static void main(String[] args){

    Tixing tixing = new Tixing(......);

    printTixing(tixing);

}

怎么用java计算梯形面积 急!!!!!

public class Test{

//梯形面积的方法

//a为梯形上底,b为梯形下底,h为梯形高,area为面积

public double area(double a,double b,double h){

double area;

//梯形面积公式:(上底+下底)*高/2

area=(a+b)*h/2;

return area;

}

//使用mian()方法实现

public static void main(String [] args){

Test t=new Test();

System.out.print("梯形面积为"+t.area(8.9,12.1,16));

}

}

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());//打印输出

}

}

1.用java定义“梯形”类,实现初始化,基本参数修改,求解面积等功能

public class Trapezoid {

private int height = 0;

private int top = 0;

private int bottom = 0;

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

setArea();

}

public int getTop() {

return top;

}

public void setTop(int top) {

this.top = top;

setArea();

}

public int getBottom() {

return bottom;

}

public void setBottom(int bottom) {

this.bottom = bottom;

setArea();

}

private int area = 0;

public Trapezoid(int height, int top, int bottom) {

this.height = height;

this.top = top;

this.bottom = bottom;

setArea();

}

public int getArea() {

return area;

}

private void setArea() {

this.area = (top + bottom) * height / 2;

}

}

关于java写梯形和梯形面积编程怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-24,除非注明,否则均为首码项目网原创文章,转载请注明出处。