There is a need to reverse an array and replace the data processing of the array smaller than 0 with 0.
Public class Test5 {public static void main (String [] args) {int [] array = new int [] {1, 3,-1, 5,-2}; System. out. println ("original array:"); for (int I = 0; I <array. length; I ++) {System. out. print (array [I] + "");} int [] newarray = getArray (array); // process data as small as 0 and process it as 0 for (int I = 0; I <newarray. length; I ++) {if (newarray [I] <0) {newarray [I] = 0 ;}} System. out. println ("\ n in reverse order and the processed array is:"); for (int j = 0; j <newarray. length; j ++) {System. out. print (newarray [j] + "");}} /*** process array inversion * @ param array * @ return */public static int [] getArray (int [] array) {int t [] = new int [array. length]; // open up a new array int count = t. length-1; for (int x = 0; x <t. length; x ++) {t [count] = array [x]; // reverse the array count --;} return t ;}}
In fact, the most critical step is
For (INT x = 0; x <t. length; X ++) {T [count] = array [X]; // array inversion count --;}
Record small knowledge for easy query.