Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/05/2006, 03:18
Avatar de dogduck
dogduck
 
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 19 años
Puntos: 19
Con JOptionPane .
Cita:
http://club.idecnet.com/~ccastano/femepa/181005.htm
http://java.sun.com/j2se/1.5.0/docs/api/
// Fig. 2.9: Addition.java
// An addition program.

// Java extension packages
import javax.swing.JOptionPane; // import class JOptionPane

public class Addition {

// main method begins execution of Java application
public static void main( String args[] )
{
String firstNumber; // first string entered by user
String secondNumber; // second string entered by user
int number1; // first number to add
int number2; // second number to add
int sum; // sum of number1 and number2

// read in first number from user as a string
firstNumber =
JOptionPane.showInputDialog( "Enter first integer" );

// read in second number from user as a string
secondNumber =
JOptionPane.showInputDialog( "Enter second integer" );

// convert numbers from type String to type int
number1 = Integer.parseInt( firstNumber );
number2 = Integer.parseInt( secondNumber );

// add the numbers
sum = number1 + number2;

// display the results
JOptionPane.showMessageDialog(
null, "The sum is " + sum, "Results",
JOptionPane.PLAIN_MESSAGE );

System.exit( 0 ); // terminate application

} // end method main

} // end class Addition