Advertisement
aaronvan

Brute-Force Search

Jul 7th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Searchers {
  5.    
  6.    public static void main(String[] args)
  7.          throws FileNotFoundException {
  8.       List<Integer> nums = readNumbers("nums.txt");
  9.       System.out.println(nums.indexOf(2));
  10.    }
  11.    
  12.    public static List<Integer> readNumbers(String filename)
  13.          throws FileNotFoundException {
  14.       List<Integer> numbers = new ArrayList<Integer>();
  15.       Scanner input = new Scanner(new File(filename));
  16.       while (input.hasNextInt()) {
  17.          numbers.add(input.nextInt());
  18.       }
  19.    return numbers;
  20.    }
  21.    
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement