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

package homework;

import java.util.Scanner;

public class Rectangle {
public static void main(String[] args) { } Scanner sc = new Scanner(System.in);
double length = sc.nextDouble();
double width = sc.nextDouble();
double area = length * width;
double per = 2 * (length + width); public void getArea() {
System.out.println("长方形的面积为:" + area);
} public void getPer() {
System.out.println("长方形的周长为:" + per);
} public void showAll() {
System.out.println("长方形的面积为" + area + ", " + "长方形的周长为:" + per+" ;");
System.out.println("长方形的长为:" + length + ", " + "长方形的宽为:" + width);
}
}

  

package homework;

import java.util.Scanner;

public class TestRectangle {

	public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入长方形的长和宽:");
Rectangle r = new Rectangle();
r.getArea();
r.getPer();
r.showAll(); }
}

  

最新文章

  1. iOS HTTP访问网络受限
  2. IIS注册.netframework4.0指令
  3. Spark源码学习1.4——MapOutputTracker.scala
  4. 向txt文件中写入换行
  5. 写一个ActionFilter检测WebApi接口请求和响应
  6. ACM题目————The Blocks Problem
  7. C# odbc
  8. 字符串匹配算法——KMP、BM、Sunday
  9. ceph 参数说明<转>
  10. java 子类继承父类成员变量的隐藏、实现方法的重写
  11. linux下的Shell编程(7)使用-x和-n调试shell程序
  12. 隔壁老主精讲web页面性能优化。
  13. 设计模式---接口隔离模式之代理模式(Proxy)
  14. BZOJ3022 : [Balkan2012]The Best Teams
  15. 1.汇编指令介绍(arm)
  16. GNU coreutils
  17. PHP中单引号与双引号的区别分析
  18. 基础笔记1(进制,浮点,递归,floor,round和ceil)
  19. linux定时任务:crontab命令
  20. nyoj 737 石子合并 http://blog.csdn.net/wangdan11111/article/details/45032519

热门文章

  1. no parameterless constructor define for type 解决一例
  2. java-Deque
  3. 用svg+css 或者js制作打钩的动画
  4. Building Applications with Force.com and VisualForce (DEV401)(五):Application Essential: Introducing Business Logic
  5. PyTorch 实战-用 Numpy 热身
  6. TensorFlow系列专题(八):七步带你实现RNN循环神经网络小示例
  7. iOS hash
  8. 简述MySQL数据库中的Date,DateTime,TimeStamp和Time类型
  9. Windows 7 NVMe补丁(包括官网下载链接)
  10. JMeter中聚合报告的各项参数详解