2 lhw1994 lhw1994 于 2016.03.12 14:18 提问

一个数组{1,-1,2,3,-1,-1,4},将里面的不为-1的数以,114,223的形式输出

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
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) {
            ssl.add(ss[i]);
        }
    }
    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) {
                ssl.add(aa[i]+""+aa[i]+""+aa[j]);
            }
        }
    }
    System.out.println(Arrays.toString(ssl.toArray()));
wwwzf123
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) {
            ssl.add(ss[i]);
        }
    }
    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) {
                ssl.add(aa[i]+""+aa[i]+""+aa[j]);
            }
        }
    }
    System.out.println(Arrays.toString(ssl.toArray()));
u013853871
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] + ",");
}
}


Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!