- Go into the "Add" sub-directory
- In your editor (e.g. Notepad++, Notepad, etc) open the file "Add.java"
- Go to "//PROGRAM STARTS HERE"
- Use the variables "n1", "n2", "result" (already declared for you)
- Get a number from the end user and put the number in the "n1" variable -- see this example
- Get a number from the end user and put the number in the "n2" variable -- see this example
- Compute the sum, e.g. result = n1 + n2;
- Show the result -- see this example
- Don't forget the semi-colons ';' at the end of the lines
- Java is picky -- If we make a typo and use "getnumberFromUser" rather than "getNumberFromUser", Java will give us an error.
- Compile and run (make sure it runs okay)
Also see
this related example
{
int n1, n2, result;
}