美文网首页
Java-1 求矩形面积

Java-1 求矩形面积

作者: M_kite | 来源:发表于2018-03-26 23:49 被阅读0次

    目的:熟悉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 求矩形面积

          本文链接:https://www.haomeiwen.com/subject/mrgdcftx.html