Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 18, 2014 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/8c216fd2982482ecdb65 to your computer and use it in GitHub Desktop.
Save Fhernd/8c216fd2982482ecdb65 to your computer and use it in GitHub Desktop.
Diálogo para calcular la suma de dos números.
import javax.swing.JOptionPane;
public class DialogoSuma
{
public static void main( String args[] )
{
// Solicitud y obtención del primer número entero como un objeto String
String numero1 = JOptionPane.showInputDialog( "Escriba el primer número entero: " );
// Conversión de tipo String a tipo Int del primer número entero
int num1 = Integer.parseInt( numero1 );
// Solicitud y obtención del segundo número entero con un objeto String
String numero2 = JOptionPane.showInputDialog( "Escriba el segundo número entero: " );
// Conversión de tipo String a tipo Int del segundo número entero
int num2 = Integer.parseInt( numero2 );
// Crear el mensaje con formato
String mensaje = String.format( "La suma: %d + %d = %d" , num1, num2 , ( num1 + num2 ) );
// Visualizar resultados en una diálogo de mensaje
JOptionPane.showMessageDialog( null, mensaje );
} // fin de main
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment