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

This is a Java Program to Illustrate a Method with 2 Parameters and Without Return Type.

Enter the length and breadth of rectangle as input. Now we pass these values as parameters to the new method where we calculate the area and print the output.

Here is the source code of the Java Program to Illustrate a Method with 2 Parameters and Without Return Type. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;
public class Rectangle
{
    double width;
    double height;
    double depth;
    void recarea(double x,double y) 
    {
        double ar = x * y;
        System.out.print("area of the rectangle is :"+ar);
    }
}
class ParameterDemo 
{
    public static void main(String args[]) 
    {
        Scanner s = new Scanner(System.in);
        System.out.print("enter length : ");
        double l = s.nextDouble();
        System.out.print("enter breadth : ");
        double b = s.nextDouble();
        Rectangle rec = new Rectangle();
        rec.recarea(l,b);
    }
}

Output:

$ javac ParameterDemo.java
$ java ParameterDemo
 
enter length : 3
enter breadth : 2
area of the rectangle is :6.0

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.