Ads

Java program to find sum and average of two integer numbers. | JAVA PROGRAMMING | JAVA LANGUAGE

 Given (input) two integer numbers and we have to calculate their SUM and AVERAGE.

Through this program, we will learn following things:

• Taking integer inputs

• Performing mathematical operations

• Printing the values on output screen



import java.util.*;

class j4
{
    public static void main(String args[])
    {
        int a, b, sum;
        float avg;


        Scanner buf = new Scanner(System.in);

        System.out.print("Enter first number : ");
        a = buf.nextInt();

        System.out.print("Enter second number : ");
        b = buf.nextInt();

        /*Calculate sum and average*/
        sum = a + b;
        avg = (float)((a + b) / 2);

        System.out.print("Sum : " + sum + "\nAverage : " + avg);
    }
}

Post a Comment

0 Comments