主方法中的java调用值为10的rect上的scale,然后打印矩形区域
我正在使用一个java助手应用程序,并被要求完成问题中所述的任务
每次我运行代码时,应用程序都会告诉我“缩放后程序应该打印矩形区域。”
我不确定我做错了什么,请看下面的代码:。。。。p、 s我仍然不能100%确定缩放意味着什么,如果有人能解释的话,我将非常感激。谢谢
public class Main
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle(100, 200);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
rect.setWidth(10);
rect.setHeight(20);
rect.scale(10);
System.out.println(rect.getArea());
}
}
class Rectangle
{
int width;
int height;
int factor;
Rectangle(int width, int height)
{
this.width = width;
this.height = height;
}
void setHeight(int height)
{
this.height = height;
}
void setWidth(int width)
{
this.width = width;
}
int getWidth()
{
return this.width;
}
int getHeight()
{
return this.height;
}
void scale(int factor)
{
width = width * factor;
height = height * factor;
}
int getArea()
{
return this.width * this.height;
}
# 1 楼答案
您的代码似乎适用于我,输出如下。您确定正在从IDE运行编译的
Main
类吗# 2 楼答案
我不确定你的{{*CD1>},但是我发现你已经用^ {< CD3>}初始化了^ {CD2>},然后你将它重置为^ {CD4>},所以你的应用程序有可能考虑它的^ ^ {CD5>}吗?我想,在那次更改之后,也许你应该打印区域
# 3 楼答案
你只需要写
rect.scale(10); System.out.println(rect.getArea());
在新的生产线,就像这条一样,在哪里
它们是分开的