Created
July 18, 2014 12:26
-
-
Save Fhernd/8c216fd2982482ecdb65 to your computer and use it in GitHub Desktop.
Diálogo para calcular la suma de dos números.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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