Java Program to Find Sum and Average of Two Integer Numbers

You are currently viewing Java Program to Find Sum and Average of Two Integer Numbers

Java program to find sum and average of two integer numbers

// Find sum and average of two numbers in Java

import java.util.*;

public class Numbers {
    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);
    }
}

Output

Enter first number : 100 
Enter second number : 200 
Sum : 300 
Average : 150.0

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply