I should be able to make use of the exceptions asking for data by console and that the string you enter should analyze me if there is any character that is not alphanumeric.
As soon as I find a non-alphanumeric character that stops.
Code:
import java.io.IOException;
import java.util.Scanner;
public class ActivitatEx3a {
public static void main(String[] args) throws IOException, Exception {
boolean var = false;
System.out.println("Entra una cadena: ");
String entradaTeclado = "";
@SuppressWarnings("resource")
Scanner entradaEscaner = new Scanner (System.in);
entradaTeclado = entradaEscaner.nextLine ();
for(int i = 0; i < entradaTeclado.length(); ++i) {
char caracter = entradaTeclado.charAt(i);
if(!Character.isLetterOrDigit(caracter)) {
System.out.println("no alfa");
}
}
}
}