Java Program to Illustrate a Method with 2 Parameters and without Return Type

Function without return type stands for a void function. The void function may take multiple or zero parameters and returns nothing. Here, we are going to define a method which takes 2 parameters and doesn’t return anything.
Syntax:
public static void function(int a, int b)
Example:Â
public static void fun1(String 1, String 2){
// method execution code
};
Approach:
- Take 2 inputs into two variables.
- Pass these inputs as an argument to the function.
- Display the sum from this defined function.
Code:
Java
// Java Program to Illustrate a Method// with 2 Parameters and without Return Typeimport java.util.*;public class Main {Â Â Â Â public static void main(String args[])Â Â Â Â {Â Â Â Â Â Â Â Â int a = 4;Â Â Â Â Â Â Â Â int b = 5;Â
        // Calling the function with 2 parameters        calc(a, b);    }    public static void calc(int x, int y)    {        int sum = x + y;        // Displaying the sum        System.out.print("Sum of two numbers is :" + sum);    }} |
Â
Â
Output
Sum of two numbers is :9
Â



