Java-1 求矩形面积

目的:熟悉java基本的写法
code:

import java.util.Scanner;
public class Rect {
double width;
    double height;
    double getArea(){
return width*height;
    }
}
class Example1{
public static void main(String args[]){
Rect rectangle;
        rectangle =new Rect();
        //Rect rectangle = new Rect();
        Scanner reader =new Scanner(System.in);
        System.out.println("input the width : ");
        rectangle.width = reader.nextDouble();
        System.out.println("input the height : ");
        rectangle.height = reader.nextDouble();
        double area = rectangle.getArea();
        System.out.print("The area of the rectangle is "+area);
    }
}

你可能感兴趣的:(Java-1 求矩形面积)