java长方形如何敲代码 用java代码画出长方形

编写java程序,输入一个长方体的长、宽、高,求长方体的表面积和体积,并将结果显示1、长方体表面积公式 :S = 2(ab + bc + ac);
2、长方体体积公式:V = abc = Sh;(这里的S表示底面积) 。
实现如下:
public class Cuboid {
// 定义长方体的长、宽、高
private double length, width, height;
public Cuboid(double length, double width, double height) {
super();
this.length = length;
this.width = width;
this.height = height;
}
// 获取当前长方体的表面积
public double getSurface() {
return getSurface(length, width, height);
}
// 获取当前长方体的体积
public double getVolume() {
return getVolume(length, width, height);
}
// 计算长方体表面积的通用方法
public static double getSurface(double length, double width, double height) {
return 2 * (length * width + width * height + length * height);
}
// 计算长方体体积的通用方法
public static double getVolume(double length, double width, double height) {
return length * width * height;
}
public static void main(String[] args) {
//1、创建长方体对象,计算当前长方体的表面积和体积
Cuboid cuboid = new Cuboid(1, 1.6, 4.8);
System.out.println(cuboid.getSurface());
System.out.println(cuboid.getVolume());
//2、使用通用方法 , 计算任意长方体的表面积和体积
System.out.println(Cuboid.getSurface(1, 1.6, 4.8));
System.out.println(Cuboid.getVolume(1, 1.6, 4.8));
}
}
java怎么编写求长方形表面积和体积的代码//主要代码System.out.print("长:")doublenum1=input.nextDouble();//代码太多以后简写System...("宽:");doublenum2=....System....("高:")double num3=....System...("表:"+(num1*num2+num1*num3+num2*num3)*2+"体积:"+n1*n2*n3)//打字不容易求给分
java中做一个按钮,点击按钮后画一个矩形的代码怎么写?兄弟帮java长方形如何敲代码你写java长方形如何敲代码了一个java长方形如何敲代码:
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
public class Print {
public static void main(String[] args) {
new Te();
}
}
class Te extends Frame implements ActionListener {
Color cc = Color.red;
int x = -20, y = -50;
Random r = new Random();
public Te() {
this.setLayout(null);
Button b = new Button("画圆");
this.add(b);
【java长方形如何敲代码 用java代码画出长方形】b.setBounds(30,30,50,50);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter () {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(200,200,500,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
this.cc = Color.red;
this.x = r.nextInt(400);
do {
int x1 = r.nextInt(300);
this.y = x1;
} while (this.y50);
this.repaint();
}
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(cc);
g.drawRect(x,y,50,50);
g.setColor(c);
}
}
java长方形Scanner scanner = new Scanner(System.in);
System.out.println("请输入长方形的长:");
int inputWidth = scanner.nextInt();
System.out.println("请输入长方形的宽:");
int inputHeight = scanner.nextInt();
int area = inputWidth * inputHeight;
int perimeter = 2*(inputWidth+inputHeight);

推荐阅读