I have a program below where an array contains some int values. It returns the array in a sequence depending whether the int value is a multiple of 10. This program does that fine, but how would I check to see if the array has no int values inside it? I get an error (Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0) Thankyou!
public class Test1{
public static void main(String[] args){
int[] nums = {};
int[] array = tenRun(nums);
int i;
for(i = 0; i < array.length - 1; i++)
System.out.print(array[i] + ", ");
System.out.println(array[i]);
}
public static int[] tenRun(int[] nums) {
int current;
int i = 0;
while(i < nums.length && nums[i] % 10 != 0)
i++;
if(i >= nums.length)
return nums;
current = nums[i];
i++;
while(i < nums.length) {
if(nums[i] % 10 == 0)
current = nums[i];
else
nums[i] = current;
i++;
}
return nums;
}
}