如何创建多数组?
吮吸代码;这是两个周期
boolean pabaiga_ciklo = false;
while (!pabaiga_ciklo)
{
System.out.println("");
System.out.println("Suma. When result: " + V);
for (int i=2; i<257; i=i*2 )
{
V = i+V;
System.out.println("Suma: " + V + " when added:: " + i);
}
V = (int) ((Math.PI * Math.pow(H, 4) * (Math.pow(R, 2)
+ Math.pow(r, 2) + Math.pow(r, 5) * Math.pow(r, 3))) / 3);
System.out.println("");
System.out.println("subtraction. With result: " + V);
for (int i=2; i<257; i=i*2 )
{
V = V-i;
System.out.println("Suma: " +V+ " when subtracted: "+i);
}
}
在控制台中显示以下结果; (一切都是我输入的)
Add. When result: 50
Sum: 52 when added: 2
Suma: 56 when added: 4
Suma: 64 when added: 8
Suma: 80 when added: 16
Suma: 112 when added: 32
Suma: 176 when added: 64
Suma: 304 when added: 128
Suma: 560 when added: 256
subtraction. With result: 50
Suma: 48 when subtracted: 2
Suma: 44 when subtracted: 4
Suma: 36 when subtracted: 8
Suma: 20 when subtracted: 16
Suma: -12 when subtracted: 32
Suma: -76 when subtracted: 64
Suma: -204 when subtracted: 128
Suma: -460 when subtracted: 256
我需要创建一个数组X [8] [16],其中值应为suma:
sum when Added sum when subtracted
1. 52 56 64 80 112 176 304 560 || 48 44 36 20 -12 -76 -204 -460
2. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
..........
8. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
如何添加它们?
答案 0 :(得分:0)
我希望这个解决方案符合您的代码所需,并且您的请求对我来说不是很清楚。
boolean pabaiga_ciklo = false;
int [ ] [ ] matrix = new double [ 8 ] [ 16 ] ;
while (!pabaiga_ciklo)
{
System.out.println("");
System.out.println("Suma. When result: " + V);
int row = 0;
for (int i=2; i<257; i=i*2 )
{
V = i+V;
System.out.println("Suma: " + V + " when added:: " + i);
matrix[0][row] = V;
row++;
}
V = (int) ((Math.PI * Math.pow(H, 4) * (Math.pow(R, 2)
+ Math.pow(r, 2) + Math.pow(r, 5) * Math.pow(r, 3))) / 3);
System.out.println("");
System.out.println("subtraction. With result: " + V);
row = 8;
for (int i=2; i<257; i=i*2 )
{
V = V-i;
System.out.println("Suma: " +V+ " when subtracted: "+i);
matrix[0][row] = V;
row++;
}
}
for (int i = 0; i < 8; i++) {
System.out.print((i + 1) + " ");
for (int j = 0; j < 16; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}