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); } }