Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fig. 2.7: Addition.java
- // Addition program that displays the sum of two numbers.
- /*import java.util.Scanner; // program uses class Scanner*/
- import javax.swing.JOptionPane; // import class JOptionPane
- public class Addition
- {
- // main method begins execution of Java application
- public static void main( String[] args )
- {
- // create a Scanner to obtain input from the command window
- /*Scanner input = new Scanner( System.in );*/
- /* int number1; // first number to add
- int number2; // second number to add
- int sum; // sum of number1 and number2*/
- /*System.out.print( "Enter first integer: " ); // prompt
- number1 = input.nextInt(); // read first number from user*/
- //prompt user for 1st int
- String number1 =
- JOptionPane.showInputDialog( "Enter first integer: ");
- /* System.out.print( "Enter second integer: " ); // prompt
- number2 = input.nextInt(); // read second number from user*/
- //prompt user for 2nd int
- String number2 =
- JOptionPane.showInputDialog( "Enter second integer: ");
- /* sum = number1 + number2; // add numbers, then store total in sum*/
- /*System.out.printf( "Sum is %d\n", sum ); // display sum*/
- //output sum of num1 and num2
- String message =
- String.format( "The sum of %s and %s is %s\n", number1, number2, number1 + number2 );
- JOptionPane.showMessageDialog( null, message );
- } // end method main
- } // end class Addition
- /**************************************************************************
- * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and *
- * Pearson Education, Inc. All Rights Reserved. *
- * *
- * DISCLAIMER: The authors and publisher of this book have used their *
- * best efforts in preparing the book. These efforts include the *
- * development, research, and testing of the theories and programs *
- * to determine their effectiveness. The authors and publisher make *
- * no warranty of any kind, expressed or implied, with regard to these *
- * programs or to the documentation contained in these books. The authors *
- * and publisher shall not be liable in any event for incidental or *
- * consequential damages in connection with, or arising out of, the *
- * furnishing, performance, or use of these programs. *
- *************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement