A.5 Another Application: Adding Integers

Our next application reads (or inputs) two integers (whole numbers, such as –22, 7, 0 and 1024) typed by a user at the keyboard, computes their sum and displays it. Programs remember numbers and other data in the computer’s memory and access that data through program elements called variables. The program of Fig. A.7 demonstrates these concepts. In the sample output, we use bold text to identify the user’s input (i.e., 45 and 72).

 1   // Fig. A.7: Addition.java 2   // Addition program that displays the sum of two numbers. 3   import java.util.Scanner; // program uses class Scanner  4  5   public class Addition 6   { 7      // main method begins execution of Java application ...

Get Android™ How to Program, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.