aide上的一题不会,特来问大家
aide吧
全部回复
仅看楼主
level 1
题目是:创建第二个 Rectangle 对象,将其分配给一个新的变量 rect2 并设置 width 为 10 , height 为 20 并打印两个字段。
我用了如下代码
public class Main
{
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
rect.width = 100;
System.out.println(rect.width);
rect.height = 200;
System.out.println(rect.height);
}{Rectangle rect2 =new Rectangle();
rect2.width = 10;
System.out.println(rect2.width);
rect2.height = 20;
System.out.println(rect2.height);}}
class Rectangle
{
int width;
int height;
}
但不知为什么只打印出来100和200 后面的rect2没打印出来,大神帮忙看看哪里错了
2016年09月16日 02点09分 1
level 11
public class Main
{
static class Rectangle
{
int width;
int height;
}
public static void main(String[] args)
{
Rectangle rect = new Rectangle();
rect.width = 100;
System.out.println(rect.width);
rect.height = 200;
System.out.println(rect.height);
Rectangle rect2 =new Rectangle();
rect2.width = 10;
System.out.println(rect2.width);
rect2.height = 20;
System.out.println(rect2.height);
}
}
2016年09月16日 03点09分 2
level 1
现在声明一个新的类 Point 以及其整数型字段 x 和 y 。
2018年01月02日 03点01分 3
1