Advertisement
witchway915

Untitled

Sep 7th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. // Fig. 2.7: Addition.java
  2. // Addition program that displays the sum of two numbers.
  3. /*import java.util.Scanner; // program uses class Scanner*/
  4. import javax.swing.JOptionPane; // import class JOptionPane
  5.  
  6. public class Addition
  7. {
  8. // main method begins execution of Java application
  9. public static void main( String[] args )
  10. {
  11. // create a Scanner to obtain input from the command window
  12. /*Scanner input = new Scanner( System.in );*/
  13.  
  14. /* int number1; // first number to add
  15. int number2; // second number to add
  16. int sum; // sum of number1 and number2*/
  17.  
  18. /*System.out.print( "Enter first integer: " ); // prompt
  19. number1 = input.nextInt(); // read first number from user*/
  20.  
  21. //prompt user for 1st int
  22. String number1 =
  23. JOptionPane.showInputDialog( "Enter first integer: ");
  24.  
  25.  
  26. /* System.out.print( "Enter second integer: " ); // prompt
  27. number2 = input.nextInt(); // read second number from user*/
  28.  
  29. //prompt user for 2nd int
  30. String number2 =
  31. JOptionPane.showInputDialog( "Enter second integer: ");
  32.  
  33.  
  34. /* sum = number1 + number2; // add numbers, then store total in sum*/
  35.  
  36. /*System.out.printf( "Sum is %d\n", sum ); // display sum*/
  37.  
  38. //output sum of num1 and num2
  39. String message =
  40. String.format( "The sum of %s and %s is %s\n", number1, number2, number1 + number2 );
  41.  
  42. JOptionPane.showMessageDialog( null, message );
  43.  
  44. } // end method main
  45. } // end class Addition
  46.  
  47. /**************************************************************************
  48. * (C) Copyright 1992-2010 by Deitel & Associates, Inc. and *
  49. * Pearson Education, Inc. All Rights Reserved. *
  50. * *
  51. * DISCLAIMER: The authors and publisher of this book have used their *
  52. * best efforts in preparing the book. These efforts include the *
  53. * development, research, and testing of the theories and programs *
  54. * to determine their effectiveness. The authors and publisher make *
  55. * no warranty of any kind, expressed or implied, with regard to these *
  56. * programs or to the documentation contained in these books. The authors *
  57. * and publisher shall not be liable in any event for incidental or *
  58. * consequential damages in connection with, or arising out of, the *
  59. * furnishing, performance, or use of these programs. *
  60. *************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement