第一章第九题(矩形的面积和周长)(Area and perimeter of a rectangle)

  • Post author:
  • Post category:其他




1.9(矩形的面积和周长)编写程序,使用以下公式计算并显示宽为4.5、长为7.9的矩形的面积和周长: 面积 = 宽 × 长



1.9 (Area and perimeter of a rectangle) Write a program that displays the area and perimeter of a rectangle with a width of 4.5 and length of 7.9 using the following formula: area = width × length

下面是参考答案代码:

public class TheAreaAndThePerimeterOfRectangleQuestion9 {
	public static void main(String[] args) {
	
		final double the_length_of_rectangle = 7.9;
		final double the_weight_of_rectangle = 4.5;
		double the_area_of_rectangle = the_length_of_rectangle * the_weight_of_rectangle;
		double the_perimeter_of_rectangle = (the_length_of_rectangle
												+ the_weight_of_rectangle) * 2.0;
		
		
		System.out.println("the area of the rectangle is " + the_area_of_rectangle);
		System.out.println("the perimeter of the rectangle is "
							+ the_perimeter_of_rectangle);
		
	}
}

运行效果:

在这里插入图片描述

注:编写程序要养成良好习惯

如:1.文件名要用英文,具体一点

2.注释要英文

3.变量命名要具体,不要抽象(如:a,b,c等等),形式要驼峰化

4.整体书写风格要统一(不要这里是驼峰,那里是下划线,这里的逻辑段落空三行,那里相同的逻辑段落空5行等等)



版权声明:本文为xjlovewjh原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。