January 2014
Intermediate to advanced
736 pages
70h 43m
English
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 ...
Read now
Unlock full access