I have a small snippet of code that will ask user to type input such as
5
12
59
58
28
58
The first number will indicate the size of the array i need to create and the rest of the numbers will be stored in that array. So with the given input an array of size 5 would be created and the numbers following would be stored in the array.
my code
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int[] array = new int[size];
for(int i =0; i<size; i++)
{
array[i] = sc.nextInt();
}
}
I was wondering is there a way of just feeding a text file instead of typing numbers manually. I mean know there are ways to read text files but is there a way to just feed it in command line. I Know in c there is some simple command where you can just type something like that and it works-> ./code.out > input.txt