Answer:
import java.util.*;
import java.util.Arrays;
public class LabProgram
{
// called function
public static int[] removeEvens(int [] nums)
{
// calculates the length of array
int len = nums.length;
int j=0;
// loop to keep count how many odd are there in array
for(int i=0;i<len;i++)
{
// condition for odd
if(nums[i]%2!=0)
{
// keeps count of odd
j++;
}
}
// declaration of array for odd nums
int newarray[] = new int[j];
j = 0;
// loop
for(int i=0;i<len;i++)
{
// condition for odd
if(nums[i]%2!=0)
{
// assigning odd number to new array
newarray[j] = nums[i];
// increment of j
j++;
}
}
// returning new array
return newarray;
}
// main program
public static void main(String[] args)
{
// array declaration
int [] input = {1,2,3,4,5,6,7,8,9};
// calling a function, passing the paramtere
int [] result = removeEvens(input);
//
System.out.println(Arrays.toString(result));
}
}
Step-by-step explanation: