zoukankan      html  css  js  c++  java
  • 4.17作业

    定义一个矩形类Rectangle:(知识点:对象的创建和使用)

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

    2 2个属性:长length、宽width

    3 创建一个Rectangle对象,并输出相关信息

     1 package chap;
     2 public class Rectangle {
     3        int length;
     4        int width;
     5     
     6         public void getArea() {
     7             System.out.println(length*width);
     8         }
     9         public void getPer() {
    10             System.out.println((length+width)*2);
    11         }
    12         public void showAll() {
    13             System.out.println("长"+lenght);
    14             System.out.println("宽"+width);
    15             System.out.println("面积:");
    16         getArea();
    17         System.out.println("周长");
    18         getPer();
    19         }
    20 }  
    21 
    22 package chap;
    23 
    24 import java.util.Scanner;
    25 
    26 public class test1 {
    27 
    28     public static void main(String[] args) {
    29         // TODO Auto-generated method stub
    30      Rectangle R= new Rectangle();
    31      Scanner input =new Scanner(System. in);
    32      System.out.println("请输入长");
    33      R.lenght=input.nextInt();
    34      System.out.println("请输入宽");
    35      R.width=input.nextInt();
    36      R.showAll();
    37      
    38     }
    39 
    40 }
  • 相关阅读:
    3164 质因数分解
    codevs3249搭积木
    codevs 2964公共素数因数
    爱改名的小融1
    单链表基础练习
    并查集(union-find sets)
    string类中字符的大小写转换
    蒜头君学英语--set()练习
    打印锯齿矩阵
    堆积木
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12736282.html
Copyright © 2011-2022 走看看