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 }
  • 相关阅读:
    Hadoop2.x环境搭建
    HDFS序列化
    Hadoop2.x介绍
    eclipse(1)----ubuntu下的安装与配置
    hive与hbase
    mysql----启动报错
    序列化+protobuff+redis
    爬虫学习笔记(2)--创建scrapy项目&&css选择器
    日常随笔
    spark学习(2)--hadoop安装、配置
  • 原文地址:https://www.cnblogs.com/WangYYY/p/12736282.html
Copyright © 2011-2022 走看看