← all problems

populateArrayFromFile 🌶️🌶️

A file's first line is an integer n, the number of values that follow after it. Each int is on its own line.

Write a method that takes a File, constructs a Scanner over it, and returns a new int array of exactly the right size, filled with those n values in order. For example, a file containing "3", then "10", "20", "30" on the following lines should produce {10, 20, 30}.