从键盘上输入长和宽java_大佬们教教我怎么把键盘输入的长和宽调到new的rectangle里...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

import java.util.Scanner;

/*

* 题目:输入:第一行是一个整数标识长方形的个数n(n<100),第二行开始分别是其长a和宽b。a,b都是整数,a,b<1000;

* 输出:他们的面积s和特性f。特性f为三个词之一。tall,short,square;如果长大于宽则显示tall,如果长小于宽则显示short,如果相等则显示square。

*/

public class Rectangle {

int a;// 长

int b;// 宽

public Rectangle() {

}

public Rectangle(int a, int b) {

this.a = a;

this.b = b;

}

public int caculateArea() {

int s = this.a * this.b;

return s;

}

public String getFeture() {

String f = "";

if (this.a > this.b) {

f = "tall";

} else if (this.a < this.b) {

f = "short";

} else {

f = "square";

}

return f;

}

public static void main(String[] args) {

Scanner n = new Scanner(System.in);

int x = n.nextInt();

int y = n.nextInt();

int z = n.nextInt();

int i = 0;

for (i = 0; i < x; i++) {

Rectangle ri = new Rectangle(y, z);

System.out.println(ri);

System.out.println(ri.caculateArea());

System.out.println(ri.getFeture());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值