Java Program to Create a Method without Parameters and Return Type

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

We have made the method to calculate area. We call this method from main method and then enter the radius of the circle as input. Now we calculate area and print the output.

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

  1. public class Test
  2. {
  3.     void areacircle()
  4.     {   
  5.         System.out.print("enter the radius :");
  6.         Scanner s = new Scanner(System.in);
  7.         float r = s.nextFloat();
  8.         float ar;
  9.         ar = (r * r) * 22 / 7;
  10.         System.out.println("area of the circle is : "+ar+" sq units.");
  11.     }
  12. }
  13. class MethodDemo
  14. {
  15.     public static void main(String args[]) 
  16.     {
  17.         Test obj = new Test();
  18.         obj.areacircle();
  19.     }
  20. }

Output:

$ javac Method_Demo.java
$ java Method_Demo
 
enter the radius :3
area of the circle is:28.285715 sq units.

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.