public
static
void
main
(string[
] args)
system.out.
println()
;}//得到有效數字的個數
int sum=0;
for(
int i =
0; i <
11; i++)}
} system.out.
println
("有效數字總和為"
+sum)
;//將有效陣列存入稀疏陣列中
int[
]array2=
newint
[sum+1]
[3];
array2[0]
[0]=
11;array2[0]
[1]=
11;array2[0]
[2]=sum;
int count=0;
for(
int i =
0; i < array1.length; i++)}
}//列印稀疏陣列
for(
int i =
0; i < array2.length; i++
)//讀取稀疏陣列
int[
] array3=
newint
[array2[0]
[0]]
[array2[0]
[1]]
;for
(int i =
1; i < array2.length; i++
)//列印
system.out.
println
("列印出存入的陣列:");
for(
int[
] ints : array3)
system.out.
println()
;}}
棋盤陣列轉稀疏存入磁碟並解析
建立二維陣列 int arr newint 11 11 初始化 arr 1 2 1 arr 2 3 2 arr 4 9 999 arr 6 6 666 system.out.println 原始棋盤 for int i 0 i arr.length i system.out.println 計算有效...
普通陣列和稀疏陣列的轉化
public class spartarray system.out.println sum 2.建立對應的稀疏陣列 int sparsearr new int sum 1 3 sparsearr 0 0 11 sparsearr 0 1 11 sparsearr 0 2 sum 遍歷二維陣列,把二...
稀疏陣列的定義和轉化
稀疏陣列 二維陣列 每個元素都是一維陣列 int arr new int 10 10 0 1 2 3 4 5 6 7 8 9 0 0,0,0,0,0,0,0,0,0,0 1 0,0,1,0,0,0,0,0,0,0 2 0,0,2,0,0,0,0,0,0,0 3 0,2,0,0,0,0,0,0,0,0...