Ola!
Gostaria de saber o motivo que meu programa esta dando um erro na hora de compilar, o programa tem que varrer a String N procurando a outra String D, tudo ocorre bem se eu nao colocar uma String muito grande.(acima de 10 caracteres já erro).
package main;
import java.util.Scanner;
public class maratona {
public static void main(String[] args) {
int d,n;
Scanner input = new Scanner(System.in);
//Atribuindo valor a tecla com defeito.
d=input.nextInt();
//Colocando as restrições.(1 ≤ D ≤ 9)
if (d<1||d>9){
System.exit(0);
}
//Atribuindo valor para ser comparado.
n=input.nextInt();
//Colocando as restrições (1 ≤ N < 10^100)
if (n<1||n>Math.pow(10,100)){
System.exit(0);
}
//Se for digitado 0 0 sair do programa.
if(d==0 && n==0){
System.exit(0);
}
//Conversão de INT>STRING
String D = new Integer(d).toString();
String N = new Integer(n).toString();
//Substituindo a "tecla" quebrada por "".
N = N.replaceAll(D,"");
//Se não houver mais nenhuma letra sair do programa.
if(N.length()<1){
System.out.print("0");
System.exit(0);
}
//Convertendo STRING>INT, Para mostrar apenas um 0 se o resultado for
//mais de um 0.
n = Integer.parseInt(N);
//Exibindo Resposta.
System.out.print(n);
}
}
//teste 7
//teste [telefone removido]
Exception in thread "main" java.util.InputMismatchException: For input string: "[telefone removido]"
at java.util.Scanner.nextInt(Scanner.java:2166)
at java.util.Scanner.nextInt(Scanner.java:2119)
at main.maratona.main(maratona.java:22)
Java Result: 1