Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Java Program to find the perimeter of a cylinder
Following is the Java code to find the perimeter of a cylinder −
Example
import java.io.*;
public class Demo{
static int find_peri(int dia, int ht){
return 2*(dia + ht);
}
public static void main(String[] args){
int dia = 7;
int ht = 15;
System.out.println("The perimeter of the cylinder is " + find_peri(dia, ht) + " units\n");
}
}
Output
The perimeter of the cylinder is 44 units
A class named Demo defines a static function that takes in two values, diameter and height. This function computes the sum of these two values and multiplies it by 2 and returns it as output. The main function defines a value each for the diameter and height. The function is called and parameters are passed to it. Relevant message is displayed on the console.
Advertisements
