2013年11月17日星期日

java loops for help online . . . .

int count = 8;
String [] [] status = {{" Column Name 1", " Column Name 2", " Column Name 3 "}, {" 3" , "5" , "1" ; } , {" 4" , "2 ", "1 "} , {" 7", " 7", " 0 "} } ;
String num = "";
for (int i = 1; i <= count; i + +) {
for (int j = 1; j if (i == Integer.parseInt (status [j] [0])) {
num = status [j] [0];
System.out.println (num);
} else {
System.out.println (" no value " + i);
}
}
}
output:
not value a
not value a
not value a
no value 2
no value 2
no value 2
3
no value 3
no value 3
no value 4
4
no value 4
no value 5
no value 5
no value 5
no value 6
no value 6
no value 6
no value 7
no value 7
7
no value 8
no value 8
no value 8


There is no master so that the output results:
not value a
no value 2
3
4
no value 5
no value 6
7
no value 8

------ Solution ------------------------------------ --------
help you change a bit
	int count=8;
String [][]status={{"列名1","列名2","列名3"},
{"3","5","1"},
{"4","2","1"},
{"7","7","0"}};
String num="";

for(int i = 1;i <= count; i ++){ 
//添加判断标准为 
int s=0;
for(int j = 1;j < status.length;j++){
if(i==Integer.parseInt(status[j][0])){
   num=status[j][0];
   System.out.println(num);
}else{
s++;
}
//如果3,4,7中都没有i的值输出
if(status.length-1==s)
System.out.println("没值"+i);
}
}

------ For reference only ----------------------------------- ----
tried one day end the cycle does not know where to put the statements , for help.
------ For reference only -------------------------------------- -
Thank you ! You can add friends , QQ: 282912050.

没有评论:

发表评论