This is our second program. It will input two numbers from the user and display their sum on the screen.
Input two numbers from the user and display their sum on the screen.
- The line 4 imports the Scanner utility in java. It will be used to create Scanner objects so that we can take input in our program.
- Line 5 defines a class which ends at line 18.
- Line 7 defines the main method which ends at line 17.
- Line 9 creates a Scanner object named input.
- Line 10 defines three int variables.
- From line 11 to 14, two values are taken from the user as input.
- At line 15, the sum of a and b is stored in the variable sum.
- At line 16, the sum is displayed on the screen.