用JAVA编程求长方形和三角形的面积和周长

2023-05-03 综合 23阅读

import java.util.Scanner;
public class Test{
 private static double length;//边长
 private static double bottom;//底
 则李private static double tall;//高
 private String perimeter;
 private String area;
 //无构造器
 private Test(){}
 //有构造器
 private void Test(double length,double bottom,double tall){
 this.length=length;
 this.bottom=bottom;
 this.tall=tall;}
 //set和get方法
 public void setlength(double length){
 this.length=length;}
 public void setbottom(double bottom){
 this.bottom=bottom;}
 public void settall(double tall){
 this.tall=tall;}
 public double getlength(){
 return this.length;}
 public double getbottom(){
 return this.bottom;}
 public double gettall(){
 return this.tall;}
 //周长和面积
 public double getperimeter(){
 return length+length+bottom;}
 public double getarea(){
 return bottom*tall/2;}
 public static void main(String[]args){
 Scanner sc = new Scanner(System.in);
 System.out.println("请输入三角形的边长");
 length = sc.nextDouble();
 System.out.println("请输入三角形的底"并困);
 bottom = sc.nextDouble();
 System.out.println("请输入三角形的绝盯念高");
 tall = sc.nextDouble();
 System.out.println("三角形的周长是:"+new Test().getperimeter()+"三角形的面积是"+new Test().getarea());
}
}

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com