The valume (V) and
surface area (A) of a hollow cylinder of height (H) bounded by external radius (R)
and internal radius (r). are given below:
 V=22/7(R^2-r^2).H
 A=2*22/7*H*(R+r)+r*22/7*(R^2-r^2)
 Write a program using user defined functions
to print the values of V and A
import
java.util.*;
class
Date
{
Scanner
sc=new Scanner (System.in);
int
R,r,H;
double
V,A;
 void takeData()
     {
          System.out.print("\nEnter
external radius:");
          R=sc.nextInt();
          System.out.print("\nEnter
internal radius:");
          r=sc.nextInt();
          System.out.print("\nEnter
Height:");
          H=sc.nextInt();
        }
   void displayArea()
   {
      
A=2*22.0/7*H*(R+r)+r*22.0/7*(Math.pow(R,2)-Math.pow(r,2));
       System.out.print("\nArea="+A);
    }
void
displayVolume()
   {
      
V=22.0/7*(Math.pow(R,2)-Math.pow(r,2))*H;
      
System.out.print("\nValume="+V); 
    }  
      public static void main(String args[])
{   
   Date ob=new Date();     
ob.takeData();
ob.displayVolume();
ob.displayArea();   
}
}
Sample Input Output
Enter
external radius:12
Enter
internal radius:10
Enter
Height:5
Valume=691.4285714285713
Area=2074.285714285714
Enter
external radius:11
Enter
internal radius:10
Enter
Height:2
Valume=132.0
Area=924.0
No comments:
Post a Comment