java计算矩形周长和面积

计算矩形周长和面积

package com.neuedu.test.chapter6;

public class zcmj2 {
 
	//声明两个属性
	public int width;
	public int heigh;
	
	//设置方法等
	public void setWidth(int width)
	{
		this.width = width;
	}
	
	public int getWidth()
	{
		return this.width;
	}
	
	public void setHeigh(int heigh)
	{
		this.heigh = heigh;
	}
	
	public int getHeigh()
	{
		return this.heigh;
	}
	
	public int zhouchang()
	{
		return (width+heigh)*2;
	}
	
	public int mianji()
	{
		return width *heigh;
	}
	public static void main(String[] args) {
		// TODO 自动生成的方法存根
        zcmj2 a = new zcmj2();
        //输入数值
        a.setWidth(50);
        a.setHeigh(10);
       
        //调用方法
        System.out.println(a.zhouchang());
        
        System.out.println(a.mianji());
	}

}

你可能感兴趣的:(java计算矩形周长和面积)