码迷,mamicode.com
首页 > 编程语言 > 详细

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

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

标签:java

/**实验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

标签:java

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!