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]Related Posts:
- Practice Programming MCQs
- Check Programming Books
- Apply for Java Internship
- Practice BCA MCQs
- Apply for Computer Science Internship