Advertisement
cd62131

HitRandom

Jun 27th, 2014
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.63 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. public class HitRandom {
  7.   public static void main(String[] args) {
  8.     int n = 5;
  9.     List<Integer> list = new ArrayList<Integer>();
  10.     Random rand = new Random();
  11.     for (int i = 0; i < n; i++) {
  12.       list.add(rand.nextInt(10) + 1);
  13.     }
  14.     Scanner in = new Scanner(System.in);
  15.     int candidate = in.nextInt();
  16.     in.close();
  17.     for (int e: list) {
  18.       if (e == candidate) {
  19.         System.out.println("Hit");
  20.         System.exit(0);
  21.       }
  22.     }
  23.     System.out.println("Miss");
  24.     System.exit(1);
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement