EXCEPCIONES 4

import javax.swing.JOptionPane;

public class DemoTryCatch {
String mensaje;
public DemoTryCatch() {
String valorCadena=JOptionPane.showInputDialog("Escribe un entero");

try{
int valorNumero=Integer.parseInt(valorCadena);
mensaje="Gracias";
}catch(NumberFormatException ex){
mensaje="No es un numero entero";
}

JOptionPane.showMessageDialog(null, mensaje);
}
 public static void main (String [] args){
new DemoTryCatch();
 }
}

No hay comentarios:

Publicar un comentario