zoukankan      html  css  js  c++  java
  • 第七周上机作业2


    1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。


    复制代码
    package test1;
    
    public class Rectangle {
        int length;
        int width;
        
        public void getArea(){
            System.out.println(length * width);
        }
    
        public void getPer(){
            System.out.println((length + width)*2);
        }
        public void showAll(){
            System.out.println("长是" + length);
            System.out.println("宽是" + width);
            System.out.println("面积是");
            getArea();
            System.out.println("周长是");
            getPer();
        }
    }
    复制代码
    package test1;
    import java.util.Scanner;
    public class Homework {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
             Rectangle a1 = new Rectangle();
             Scanner input = new Scanner(System.in);
             System.out.print("请输入长:");
             a1.length = input.nextInt();
             System.out.print("请输入宽:");
             a1.width = input.nextInt();
             a1.showAll();
        }
    
    }
  • 相关阅读:
    prayer OJ M
    51nod1295
    纪念第一次ak。。。
    noip2007-4
    51nod1344
    51nod1079
    51nod1537
    51nod1269Devu and Flowers
    python基本数据类型之列表list
    Python基本数据类型
  • 原文地址:https://www.cnblogs.com/wishings/p/12732173.html
Copyright © 2011-2022 走看看