zoukankan      html  css  js  c++  java
  • 第十次作业

    定义一个矩形类Rectangle:(知识点:对象的创建和使用)
    1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。
    2 有2个属性:长length、宽width
    3 创建一个Rectangle对象,并输出相关信息

    package aaad;
    
    import java.util.*;
    
    public class bbb {
    
    
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            asd mjm = new asd();
     
    
            Scanner input = new Scanner(System.in);
            System.out.println("输入长为:");
            mjm.length = input.nextInt();
            System.out.println("输入宽为:");
            mjm.width = input.nextInt();
    
           mjm.showAll();
    
        }
    }
    package aaad;
    
    public class asd {
    
              int length;
                int width;
    
                public void showAll() {
                    System.out.println("长是" + length + ",宽是" + width);
                    System.out.println("可得面积是:");
                    getArea();
                    System.out.println("周长是:");
                    getPer();
    
                }
    
                
                public void getArea() {
                    System.out.println(length * width);
                }
    
                
                public void getPer() {
                    System.out.println((length + width) * 2);
                }
    
            }

  • 相关阅读:
    ubutu16.04编译安装apache
    python格式化字符串
    git服务器搭建
    merge into 导致序列跳号
    Apache 强制SSL访问
    pyhton之解析html的表格
    Two modules in a project cannot share the same content root报错解决方案
    hdoj
    hdoj
    QHUOJ
  • 原文地址:https://www.cnblogs.com/dhy-com/p/12744019.html
Copyright © 2011-2022 走看看