Use zero length array

xiaoxiao2021-03-06  107

Assume that a filter data is written. For example, to obtain a given range of data in an array, write a method to remove data in the array, return a new array.

How to implement this method, one method is: import java.util. *; Public class zerodemo1 {// filter invrit is def [] FilterData (int indata [], int minval, int maxval) {// check parameters for errors if (indata == null) {throw new NullPointerException ( "indata is null");} if (maxval = minval && Indata [II] <= maxval) {Validcnt ;}} // if no valid value, return null if (validcnt == 0) {Return Null;} // Copy Vali D VALUES TO New Array // and return it int outdata [] = new int [validcnt]; for (int II = 0, j = 0; II = Minval && Indata [II] <= maxval) {Outdata [J ] = Indata [II];}} return outdata;}}} return outdata; New int [] {1, 3, -17, 8, 59};

// filter out value Not in the Range 1-10 int outdata1 [] = filterdata (INDATA, 1, 10); for (int II = 0; II

转载请注明原文地址:https://www.9cbs.com/read-123498.html

New Post(0)