Olá pessoal, estou com o código em java abaixo que não está lendo o arquivo txt, ocorre uma exceção. O arquivo contém as strings: criacao, cadeira, mesa, armario, praia.
Alguém tem ideia do que possa estar ocorrendo? Pelo que já li por aqui a posição da informação no arquivo pode estar influenciando mas não consegui descobrir até agora.
Exception in thread “main” java.lang.NumberFormatException: For input string: "criacao"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at implementacao.FlaviusJosephus.main(FlaviusJosephus.java:18)
package implementacao;
import java.io.*;
public class FlaviusJosephus
{
public static void main (String[] args)
throws IOException
{
File file = new File(“C:/Users/lista.txt”);
@SuppressWarnings(“resource”)
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while ((line = in.readLine()) != null) {
line = line.trim();
String[] split = line.split(", ");
int total = Integer.parseInt(split[0]);
int next = Integer.parseInt(split[1]);
boolean[] killed = new boolean[total];
int current = 0;
for (int i = 0; i < total; i++) {
int count = 0;
while (true) {
if (!killed[current]) {
count++;
if (count == next) {
break;
}
}
current++;
current %= total;
}
killed[current] = true;
System.out.print(current);
if (i+1 != total) {
System.out.print(" ");
}
}
System.out.println();
}
}