JTF > Demo Gallery > Simple Programs > Add2

This package contains two versions of a program to add two numbers entered by the user. The code for the Add2Console class looks like this:

 
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 + ".");
   }
}

The code for the Add2Dialog class is the same except for the header line, which extends DialogProgram instead.