In this program we will find the average of two numbers. To find average of two numbers, they are added and their sum is divided by two.
Input two numbers from the user and display their average 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 double variables.
- From line 11 to 14, two values are taken from the user as input.
- At line 15, the average of a and b is calculated and stored in the variable avg.
- At line 16, the average is displayed on the screen.