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.
public class Test
{
void areacircle()
{
System.out.print("enter the radius :");
Scanner s = new Scanner(System.in);
float r = s.nextFloat();
float ar;
ar = (r * r) * 22 / 7;
System.out.println("area of the circle is : "+ar+" sq units.");
}
}
class MethodDemo
{
public static void main(String args[])
{
Test obj = new Test();
obj.areacircle();
}
}
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
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
Related Posts:
- Check Java Books
- Check Programming Books
- Apply for Java Internship
- Practice Programming MCQs
- Apply for Computer Science Internship