我已经尝试解决这个问题几个小时:为什么当 l 循环还没有完成时 j 和其他变量会发生变化?这是我的代码:
public class main
{
public static void main (String[] args)
{
String name=args[0];
double a=Double.parseDouble(args[1]);
double b=Double.parseDouble(args[2]);
double c=Double.parseDouble(args[3]);
double d=Double.parseDouble(args[4]);
//for complexes
for (double i = -a; i<=a; i++){
for (double j = -b; j<=b; j++){
for (double k = -c; k<=c; k++){
for (double l = -d; l<=d; l++){
complex c1 = new complex (i, j);
complex c2 = new complex (k, l);
System.out.println(c1+"; "+c2);
}
}
}
}
}
}
//And the complex class:
public class complex {
private static double c;
private static double n;
public complex(double c, double n){
this.c=c;
this.n=n;
}
public String toString(){
if ((n==0)&&(c==0))
return "0";
if (n==0)
return ""+c;
if (c==0)
return ""+n+"i";
else return ""+c+"+"+n+"i";
}
}
输出是:
-1.0+-2.0i; -1.0+-2.0i
-1.0+-1.0i; -1.0+-1.0i
-1.0; -1.0
-1.0+1.0i; -1.0+1.0i
-1.0+2.0i; -1.0+2.0i
-2.0i; -2.0i
-1.0i; -1.0i
0; 0
1.0i; 1.0i
ect.
但输出应该是
-1.0-2.0i; -1.0-2.0i
-1.0-2.0i; -1.0-1.0i
-1.0-2.0i; -1.0
-1.0-2.0i; -1.0+1.0i
-1.0-2.0i; -1.0+2.0i
-1.0-2.0i; -2.0i
ect.
但是复杂类中的任何东西都不重要,对吧?因为即使我使用了同名的变量,它们也不应该从他们的类之外访问,对吧?非常感谢您的帮助!我也问过其他人,也没有人能够发现我的错误,所以任何事情都非常感谢。
编辑:
我之前没有发布完整的输出。这是我得到的输出:
-1.0+-2.0i; -1.0+-2.0i
-1.0+-1.0i; -1.0+-1.0i
-1.0; -1.0
-1.0+1.0i; -1.0+1.0i
-1.0+2.0i; -1.0+2.0i
-2.0i; -2.0i
-1.0i; -1.0i
0; 0
1.0i; 1.0i
2.0i; 2.0i
1.0+-2.0i; 1.0+-2.0i
1.0+-1.0i; 1.0+-1.0i
1.0; 1.0
1.0+1.0i; 1.0+1.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