Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // game loop
- while (true) {
- int count = in.nextInt(); // The number of current enemy ships within range
- String closestEnemy = "";
- int minDist = 1000;
- for (int i = 0; i < count; i++) {
- String enemy = in.next(); // The name of this enemy
- int dist = in.nextInt(); // The distance to your cannon of this enemy
- if(dist <= minDist) {
- minDist = dist;
- closestEnemy = enemy;
- }
- }
- System.out.println(closestEnemy); // The name of the most threatening enemy (HotDroid is just one example)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement