lhw1994 于 2016.03.12 14:18 提问

java 一个int a[ ]={1,-1,2,3,-1,-1,4},将里面的不为-1的数以112,113,114,221,223,224,331,332，334的形式输出
java 一个int a[ ]={1,-1,2,3,-1,-1,4},将里面的不为-1的数以112,113,114,221,223,224,331,332，334的形式输出
java 一个int a[ ]={1,-1,2,3,-1,-1,4},将里面的不为-1的数以112,113,114,221,223,224,331,332，334的形式输出

3个回答

wwwzf123   2016.03.12 16:29
``````int ss[] = new int[]{1,-1,2,3,-1,-1,4};
List ssl = new ArrayList();
for(int i=0;i<ss.length;i++) {
if(ss[i] != -1) {
}
}
Object[] aa = ssl.toArray();
ssl.clear();
for(int i = 0;i<aa.length-1;i++) {
for(int j=0;j<aa.length;j++) {
if(i!=j) {
}
}
}
System.out.println(Arrays.toString(ssl.toArray()));
``````
wwwzf123   2016.03.12 16:29
``````int ss[] = new int[]{1,-1,2,3,-1,-1,4};
List ssl = new ArrayList();
for(int i=0;i<ss.length;i++) {
if(ss[i] != -1) {
}
}
Object[] aa = ssl.toArray();
ssl.clear();
for(int i = 0;i<aa.length-1;i++) {
for(int j=0;j<aa.length;j++) {
if(i!=j) {
}
}
}
System.out.println(Arrays.toString(ssl.toArray()));
``````
u013853871   2016.03.12 16:37

public class Test2 {
public static void main(String[] args) {
int[] array = {1,-1,2,3,-1,-1,4};
System.out.print(array[0]);
System.out.print(array[0]);
System.out.print(array[2] + ",");
System.out.print(array[0]);
System.out.print(array[0]);
System.out.print(array[3] + ",");
System.out.print(array[0]);
System.out.print(array[0]);
System.out.print(array[6] + ",");
System.out.print(array[2]);
System.out.print(array[2]);
System.out.print(array[0] + ",");
System.out.print(array[2]);
System.out.print(array[2]);
System.out.print(array[3] + ",");
System.out.print(array[2]);
System.out.print(array[2]);
System.out.print(array[6] + ",");
System.out.print(array[3]);
System.out.print(array[3]);
System.out.print(array[0] + ",");
System.out.print(array[3]);
System.out.print(array[3]);
System.out.print(array[2] + ",");
System.out.print(array[3]);
System.out.print(array[3]);
System.out.print(array[6] + ",");
}
}

``````
``````