Given a file compact.txt that contains no more than 100 integers greater than 0, you need to read the file into an array, then traverse the array removing all the zeros keeping the original order of numbers in tact. And below is my unfinished code.
import java.io.File;
import java.util.Scanner;
public class CompactUtil {
private static Scanner scan;
static int[] num = new int[100];
public static int[] readInArray(String filePath){
try{
scan = new Scanner(new File(filePath));
for(int x=0; scan.hasNext(); x++){
num[x]=scan.nextInt();
System.out.print("the original array is : "+num[x]);
}
}catch(Exception e){
System.out.println("You got: "+e.getMessage());
}
return num;
}
private static int[] removeAndShift(int[] nums, int index){
for()
}
public static int[] removeZeros(int[] nums){
}
public static void printArray(int[] nums){
}
}
public class Driver {
public static void main(String[] args) {
int[] num = CompactUtil.readInArray("H:/compact.txt");
}
}