第十次作业

1 定义三个方法:getArea()求面积、getPer()求周长,showAll()分别在控制台输出长、宽、面积、周长。

package ydy3;

public class test3{

int length;
int width;
public static void main(String[] args){}
public void getArea() {
int a=width*length;
System.out.println("面积"+a);
}
public void getPer() {
int b=(width+length)*2;
System.out.println("周长:"+b);
}
public void showAll() {
System.out.println("宽:"+width);
System.out.println("长"+length);
getPer();
getArea();

}
}

package ydy3;
import java.util.Scanner;

public class test3{

Rectangle a1 = new Rectangle();
Scanner input = new Scanner(System.in);
System.out.print("请输入长:");
a1.length = input.nextInt();
System.out.print("请输入宽:");
a1.width = input.nextInt();
a1.showAll();
}

原文地址:https://www.cnblogs.com/ydy128/p/12750219.html