Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.Scanner;
- public class HitRandom {
- public static void main(String[] args) {
- int n = 5;
- List<Integer> list = new ArrayList<Integer>();
- Random rand = new Random();
- for (int i = 0; i < n; i++) {
- list.add(rand.nextInt(10) + 1);
- }
- Scanner in = new Scanner(System.in);
- int candidate = in.nextInt();
- in.close();
- for (int e: list) {
- if (e == candidate) {
- System.out.println("Hit");
- System.exit(0);
- }
- }
- System.out.println("Miss");
- System.exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement