Java Program to Print Average of 3 Number using Function

 In this example we can enter 3 numbers from the user & make a function to print their average.

This program asks the user to enter 3 numbers and we can create a function to print their average of 3 numbers.


import java.util.Scanner;

public class Main {
    static void avgs(int x, int y, int z) {
        float avg = (x+y+z)/3f;
        System.out.print(avg);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        avgs(a, b, c);
    }
}
Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.