Java Program To Find Average Of Two Numbers

Write Java program to compute the average of two numbers

// WAP to find average of two nteger numbers   

import java.util.Scanner;
public class Average 
{
    public static void main(String[] args)
    {
        int n1,n2;
        
        // object 'sc' created to scan data
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter number 1 :--> ");
        n1 = sc.nextInt();

        System.out.println("Enter number 2 :--> ");
        n2 = sc.nextInt();

        float avg = (n1+n2)/2;

        System.out.println("Average of (" + n1 + " + " + n2 + ") / 2 = " + avg);

    }    
}

Outupt:


<< Previous | Next >>


Leave a Reply

Your email address will not be published.