public class DenoShow7 {
public static void main(String[] args) {
int[] array=new int[]{1,3,-1,5,-2};
System.out.println("原数组为:");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]+" ");
}
System.out.println();
//对数组进行反转
for (int i = 0,end=array.length-1; i < end; i++,end--) {
int temp=array[i];
array[i]=array[end];
array[end]=temp;
}
System.out.println("逆序处理后的数组为:");
//判断条件,遍历存进新数组
for (int i = 0; i < array.length; i++) {
if (array[i]<0) {
array[i]=0;
}
int[] newarray={array[i]};
for (int j = 0; j < newarray.length; j++) {
System.out.print(newarray[j]+" ");
}
}
}
}
看一下,应该对你有帮助 |