college/ss2010/gdi2/java/libs/acm/demo/Add2Program.java
2013-12-19 19:05:28 +01:00

27 lines
660 B
Java

/*
* File: Add2Program.java
* ----------------------
* This program adds two numbers and prints their sum. Because
* this version is a Program, input and output are assigned to
* System.in and System.out.
*/
import acm.program.*;
public class Add2Program extends Program {
public void run() {
println("This program adds two numbers.");
int n1 = readInt("Enter n1: ");
int n2 = readInt("Enter n2: ");
int total = n1 + n2;
println("The total is " + total + ".");
}
/* Standard Java entry point */
/* This method can be eliminated in most Java environments */
public static void main(String[] args) {
new Add2Program().start(args);
}
}