Thursday, September 2, 2010
Assignment #4 Addition.java
//Assignment 4 Addition.java
import javax.swing.JOptionPane;
public class Addition
{
public static void main(String args[] )
{
//obtain user input from JOptionPaneinput dialogs
String firstNumber =
JOptionPane.showInputDialog( "Enter first interger" ) ;
String secondNumber =
JOptionPane.showInputDialog( "Enter second integer" ) ;
//convert string into int values
int number1 = Integer.parseInt( firstNumber ) ;
int number2 = Integer.parseInt( secondNumber ) ;
int sum = number1 + number2;
//display results in JOptionPane mssg dialog
JOptionPane.showMessageDialog( null, "The sum is " + sum,
"Sum of Two Integers", JOptionPane.PLAIN_MESSAGE) ;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment