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

27 lines
659 B
Java

/*
* File: Add2Console.java
* ----------------------
* This program adds two numbers and prints their sum. Because
* this version is a ConsoleProgram, the input and output appear
* on the console.
*/
import acm.program.*;
public class Add2Console extends ConsoleProgram {
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 Add2Console().start(args);
}
}