首页 > 编程语言 > 详细

那些年,一起学的Java 3-4

时间:2015-03-13 01:58:58      阅读:178      评论:0      收藏:0      [点我收藏+]

/**实验3.4

 * 使用上题的矩形类,编程统计若干块土地的相关信息

 * 由用户输入每块儿土地的长与宽,程序将相关结果输出

 **/

import java.util.*;
public class adu
{
	public static void main (String[] args)
	{
		Rectangle rectangle1 = new Rectangle();
		Rectangle rectangle2 = new Rectangle();
		System.out.print("Input  length and width of the rectanle1: ");
		Scanner in = new Scanner (System.in);
		int rectangle1Length = in.nextInt();
		int rectangle1Width = in.nextInt();
		System.out.println("The perimeter of rectangle1 is: " + rectangle1.perimeter(rectangle1Length, rectangle1Width));
		System.out.println("The area of rectangle1 is: " + rectangle1.area(rectangle1Length, rectangle1Width));
		
		System.out.print("Input  length and width of the rectanle2: ");
		int rectangle2Length = in.nextInt();
		int rectangle2Width = in.nextInt();
		System.out.println("The perimeter of rectangle2 is: " + rectangle2.perimeter(rectangle2Length, rectangle2Width));
		System.out.println("The area of rectangle2 is: " + rectangle2.area(rectangle2Length, rectangle2Width));
	}
}

class Rectangle
{
	private int length;
	private int width;
	Rectangle(int l, int w)
	{
		this.length = l;
		this.width = w;
	}
	Rectangle ()
	{
		
	}
	 int perimeter (int length, int width)
	{
		return (length + width) * 2;
	}
	 int area (int length, int width)
	{
		return length * width;
	}
}


那些年,一起学的Java 3-4

原文:http://anglecode.blog.51cto.com/5628271/1619845

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!