public class RectangleArea { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the length : "); double length = scanner.nextDouble(); System.out.print("Enter the width : "); double width = scanner.nextDouble(); scanner.close()...
Write a Java program to print the area and perimeter of a rectangle. Java: Perimeter of a rectangle A perimeter is a path that surrounds a two-dimensional shape. The word comes from the Greek peri (around) and meter (measure). The perimeter can be used to calculate the length of fence ...
// Define the Main classpublicclassMain{// Define the main method which is the entry point of the programpublicstaticvoidmain(String[]args){// Create an instance of the Rectangle class with the width 7 and height 12Rectanglerectangle=newRectangle(7,12);// Print the area of the rectangle ...
Rectangle(double w, double h) { width=w; height=h; } public double getPerimeter() { return 2*( width+height);} public double getArea() { return width*height; } public String toString() { return "width="+width+",height="+height+ ",perimeter="+getPerimeter()+",area="+getArea();...
of the union of all rectangles. The input and output are files specified in program arguments. Input is represented by N lines with 4 numbers separated by spaces, defining 2 opposite vertices of the rectangle. Output file should contain 1 number - the resulting area of the rectangles' union....
When you compile this program, you will find that two class files have been created, one for Rectangle and one for RectangleArea. The Java compiler automatically puts each class into its own class file.
{ get; set; } public double GetArea() { return Width * Height; } } class Program { static void Main(string[] args) { Rectangle rectangle = new Rectangle { Width = 5, Height = 10 }; Console.WriteLine("Area of rectangle: " + rectangle.GetArea()); // 输出 "Area of rectangle: 50...
After this, the variables l and b of object rect are multiplied and the result is stored in variable a which is then displayed on the screen. class Rect{ int l,b;}class CalAreaofRectangle{ public static void main (String args[]) { int a; Rect rect = new Rect(); rect.l=20; ...
Circle: area=50.27, Volumn=0.00 Clinder: area=251.33, Volumn=235.62 此处给出主函数 public class ShapeTest { public static void main(String[] args) { Shape s[] = new Shape[3]; s[0] = new Rectangle(2,3); s[1] = new Circle(4); ...
* @param width 矩形的宽度 * @param height 矩形的高度 */ public Rectangle(int width, int height) { this.width = width; this.height = height; } /** * 计算矩形的面积。 * @return 矩形的面积 */ public int calculateArea() { return width * height; } } 通过JavaDoc注释,我们可以清楚地...