I am trying to print output Win or Lose based on input but getting error. Please below the question for my code -
A new fighting game has become popular. There is n number of villains in it, each having some strength. There are n players in the game with each having some energy. The energy is used to kill the villains. A villain can be killed only if the energy of the player is greater than the strength of the villain.
Maxi is playing the game and at a particular time wants to know if it is possible for him to win the game or not with the given set of energies and strengths of players and villains. Maxi wins the game if his players can kill all the villains with the allotted energy.
Input Format The first line of input consists of a number of test cases, T. The first line of each test case consists of a number of villains and player, N. The second line of each test case consists of the N space-separated by strengths of Villains. The third line of each test case consists of N space-separated by the energy of players.
Error message
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Main.main(Main.java:8)
My Code
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int numberOfTestcases = input.nextInt();
for (int k = 0; k < numberOfTestcases; k++) {
int number = input.nextInt();
System.out.println(number + "");
// Scanner input = new Scanner(System.in);
int[] players_energy = new int[number];
int[] villain_strength = new int[number];
for (int i = 0; i < villain_strength.length; i++) {
System.out.println("Please enter villain strengths ");
villain_strength[i] = input.nextInt();
}
for (int i = 0; i < players_energy.length; i++) {
System.out.println("Please enter player energies ");
players_energy[i] = input.nextInt();
}
for (int i = 0; i < players_energy.length; i++) {
System.out.println("player energies are " + players_energy[i] + "");
}
for (int i = 0; i < villain_strength.length; i++) {
System.out.println("villain strengths are " + villain_strength[i] + "");
}
Arrays.sort(players_energy);
Arrays.sort(villain_strength);
for (int i = 0; i < players_energy.length; i++) {
System.out.println("player energies after sorting are " + players_energy[i] + "");
}
for (int i = 0; i < villain_strength.length; i++) {
System.out.println("villain strengths after sorting are " + villain_strength[i] + "");
}
boolean result = true;
for (int i = 0; i < number; i++) {
if (players_energy[i] > villain_strength[i]) {
result = true;
} else {
result = false;
}
}
if (result) {
System.out.println("WIN");
} else {
System.out.println("LOSE");
}
}
}
}