我有个数组如下:
String[][] arrA = {(0,20},(1,21),(2,22),(3,22),(4,23),(5,20),(6,23),(7,24),(8,20)...};想按每隔3个取出来一维中数值,其余一维为空,二维中所有数保留,结果赋值给另一个数组:arrB = {(0,20),("",21),("",22),("",22),(4,23),("",20),("",20),("",23),(7,24),("",20),...};这个怎么写啊?
String[][] arrA = {(0,20},(1,21),(2,22),(3,22),(4,23),(5,20),(6,23),(7,24),(8,20)...};想按每隔3个取出来一维中数值,其余一维为空,二维中所有数保留,结果赋值给另一个数组:arrB = {(0,20),("",21),("",22),("",22),(4,23),("",20),("",20),("",23),(7,24),("",20),...};这个怎么写啊?
public static void main(String[] args) {
String[][] arr = { { "0", "20" }, { "1", "21" }, { "2", "22" },
{ "3", "22" }, { "4", "23" }, { "5", "20" }, { "6", "23" },
{ "7", "24" }, { "8", "20" } };
for (int i = 1; i < arr.length; i++) {
for (int j = 0; j < 2; j++) {
if (i % 4 != 0) {
arr[i][0] = " ";
}
}
} for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i][0] + ",");
System.out.print(arr[i][1]);
System.out.println();
}
}
* @param args
*/
public static void main(String[] args) {
String[][] str = {{"0", "20"},{"1", "21"},{"2", "22"},{"3", "23"},{"4", "24"},{"5", "25"},{"6", "26"},
{"7", "27"},{"8", "28"},{"9", "29"},{"10", "30"},{"11", "31"},};
String[][] strB = str;
for(int i=0; i<strB.length; i++) {
for(int j=0; j<strB[i].length; j++) {
System.out.print(strB[i][j] + "\t");
}
System.out.println();
}
int count = 4;
for(int i=0; i<str.length; i++, count++) {
if(count == 4){
count = 0;
} else {
str[i][0] = "";
}
}
System.out.println("-----------------");
for(int i=0; i<strB.length; i++) {
for(int j=0; j<strB[i].length; j++) {
System.out.print(strB[i][j] + "\t");
}
System.out.println();
}
}}
public class Test { /**
* @param args
*/
public static void main(String[] args) {
String[][] str = {{"0", "20"},{"1", "21"},{"2", "22"},{"3", "23"},{"4", "24"},{"5", "25"},{"6", "26"},
{"7", "27"},{"8", "28"},{"9", "29"},{"10", "30"},{"11", "31"},};
String[][] strB = str;
for(int i=0; i<strB.length; i++) {
for(int j=0; j<strB[i].length; j++) {
System.out.print(strB[i][j] + "\t");
}
System.out.println();
}
int count = 4;
for(int i=0; i<str.length; i++, count++) {
if(count == 4){
count = 0;
} else {
str[i][0] = "";
}
}
System.out.println("-----------------");
for(int i=0; i<strB.length; i++) {
for(int j=0; j<strB[i].length; j++) {
System.out.print(strB[i][j] + "\t");
}
System.out.println();
}
}}
public class Test6 {
public static void main(String args[]){
String[][] arrA = {{"0","20"},{"1","21"},{"2","22"},{"3","22"},{"4","23"},{"5","20"},{"6","23"},{"7","24"},{"8","20"}};
String[][] arrB = arrA;
int count = 0;
for(int i = 0;i < arrB.length; i++){
if(count % 4 != 0)
arrB[i][0] = " ";
count++;
}
for(int i = 0; i < arrB.length; i++){
for(int j = 0; j < arrB[i].length; j++)
System.out.print(" "+ arrB[i][j]);
System.out.println();
}
}
}
你那个arrB指向arrA,把arrA操作掉了…………