aaronvan icon

Brute-Force Search

aaronvan | PRO | 07/07/18 03:13:28 PM UTC | 0 ⭐ | 455 👁️ | Never ⏰ | []
Java |

580 B

|

None

|

0 👍

/

0 👎

import java.io.*;
import java.util.*;
 
public class Searchers {
   
   public static void main(String[] args)
         throws FileNotFoundException {
      List<Integer> nums = readNumbers("nums.txt");
      System.out.println(nums.indexOf(2));
   }
   
   public static List<Integer> readNumbers(String filename)
         throws FileNotFoundException {
      List<Integer> numbers = new ArrayList<Integer>();
      Scanner input = new Scanner(new File(filename));
      while (input.hasNextInt()) {
         numbers.add(input.nextInt());
      }
   return numbers;
   }
   
}

Comments