負の値から正の値まで、ユーザーが指定した範囲内のすべてのペアを生成するネストされた for ループを作成しようとしています。説明するのは少し難しいですが、ここに私が持っているコードがあります:
public class test method {
public static void main (String[] args) {
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = 3;
int d = 4;
for (int i = -a; i <= a; i++)
for (int j = -b; j <= b; j++) {
System.out.println(a+" and "+b+" vs "+c+" and "+d+"\n");
}
}
}
コマンド ライン引数 1 と 2 を指定すると、目的の出力は次のようになります。
-1 と -2 対 3 と 4
-1 と -1 vs 3 と 4
-1 と 0 vs 3 と 4
-1 と 1 vs 3 と 4
-1 と 2 vs 3 と 4
0 と -2 対 3 と 4
0 と -1 vs 3 と 4
0 と 0 vs 3 と 4
0 と 1 vs 3 と 4
0 と 2 vs 3 と 4
1 と -2 対 3 と 4
1 と -1 vs 3 と 4
1 と 0 vs 3 と 4
1 と 1 vs 3 と 4
1 と 2 vs 3 と 4