How do I create an array whose size is equal to the size of a file? The file name is passed as argument to main
.
public static void main(String[] args){
File text = new File(args[0]); //file input
Scanner input = null;
try {
input = new Scanner(text);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int[] A = new int[??????]; //what should be size 2 match file
}
while(input.hasNextInt()){
for(int i = 0;i
if(A[i]%2 == 0)System.out.println("1");
else System.out.println("0");
}
i want to use it in this code, but when i run this code with any random size of Array A, and if the number of entries in the file is less than the size of A then it throws "No such elements exception" so i figured if i can get the size of file to be the size of A it wont happen, right? – ajsum0 Feb 12 '15 at 13:13