class Tixing //梯形類

成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計、成都網(wǎng)站設(shè)計與策劃設(shè)計,臨泉網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:臨泉等地區(qū)。臨泉做網(wǎng)站價格咨詢:18982081108
{
private float Height; //高
private float upBotton;//上底
private float downBotton;//下底
public Tixing(float Height,float upBotton,float downBotton)//構(gòu)造方法
{
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);//構(gòu)造
System.out.println("梯形的面積是:"+t.getTixingArea());//打印輸出
}
}
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("命令行參數(shù)錯誤");
}
}
javac xxx.java
java xxx 2 4 5
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()));
}
}
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()方法實現(xiàn)
public static void main(String [] args){
Test t=new Test();
System.out.print("梯形面積為"+t.area(8.9,12.1,16));
}
}
因為這3個圖形的面積計算,需要的參數(shù)分別是1個,2個,3個。
所以你可以寫3個方法,方法名字都一樣,但是第一個方法有1個參數(shù)
第二個方法有2個參數(shù),但三個方法有3個參數(shù)。這樣完全不會混淆
package test;
public class Test{
public static void main(String[] args) {
Lader l=new Lader(4, 8, 3);
System.out.println("體形面積是"+l.computerArea());
}
}
class Lader {
private float above; //梯形的上底(變量聲明)
private float bottom; //梯形的下底(變量聲明)
private float height; //梯形的高(變量聲明)
private float area; //梯形的面積(變量聲明)
public float computerArea() { //計算面積(方法)
area = (above+bottom)*height/2.0f;
return area;
}
public Lader(float above,float bottom,float height){
this.above=above;
this.bottom=bottom;
this.height=height;
}
void setHeight(float h) { //修改高(方法)
height = h;
}
public float getAbove() {
return above;
}
public void setAbove(float above) {
this.above = above;
}
public float getBottom() {
return bottom;
}
public void setBottom(float bottom) {
this.bottom = bottom;
}
public float getArea() {
return area;
}
public void setArea(float area) {
this.area = area;
}
public float getHeight() {
return height;
}
}
標(biāo)題名稱:java求梯形的面積代碼 java求梯形的面積代碼是多少
當(dāng)前URL:http://www.chinadenli.net/article20/hpgoco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、微信公眾號、網(wǎng)站設(shè)計、定制網(wǎng)站、用戶體驗、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)