以下代码块将输出设为0.
public class HelloWorld{
public static void main(String []args){
int product = 1;
for (int i = 10; i <= 99; i++) {
product *= i;
}
System.out.println(product);
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么会这样吗?
我知道String是java.lang中的最后一个类,所以像string类一样可以使用plus(+)运算符追加其他类.
例如我有一个类:
public class Foo{
public int x;
public int y;
public Foo(int x,int y){
this.x=x;
this.y=y;
}
public Foo append(int x,int y){
return new Foo(this.x+x,this.y+y);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,是否可以添加两个类,如下所示:
Foo a=new Foo(2,3),b=new Foo(3,4);
Foo c=a+b;
System.out.println(c.x+" "+c.y);
Run Code Online (Sandbox Code Playgroud)
得到这样的输出:
5 7
Run Code Online (Sandbox Code Playgroud)
如果是的话,我还需要做什么,如果没有原因?