Thursday, September 4, 2025
HomeLanguagesJavaJava Program to Illustrate a Method with 2 Parameters and without Return...

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:

  1. Take 2 inputs into two variables.
  2. Pass these inputs as an argument to the function.
  3. Display the sum from this defined function.

Code:

Java




// Java Program to Illustrate a Method
// with 2 Parameters and without Return Type
import 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

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS