Hello
I am stuck in this problem, I have tried many ways to find the error that gives me Runtime Error but I can not find it, I thought my code was O.K but not, any suggestions? The problem is 4071 - "Bubble Gum, Bubble Gum, in the dish, how many pieces do you wish?", and this is my code, I hope you can help me thanks
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(bf.readLine());
String listNames = "";
String nameChosen = "";
int piecesGum = 0;
for (int i = 0; i < t; i++) {
listNames = bf.readLine();
nameChosen = bf.readLine();
piecesGum = Integer.parseInt(bf.readLine());
solve(listNames, nameChosen, piecesGum);
}
}
public static void solve(String listNames, String nameChosen, int piecesGum) {
String[] names = listNames.split(" ");
int pos = 0;
for (int j = 0; j < names.length; j++) {
if (names[j].equals(nameChosen)) {
pos = j;
}
}
//System.out.println(names[((n - 1) % names.length) + pos]);
System.out.printf("%s%n",names[((piecesGum - 1) % names.length) + pos]);
}
}