Header Ads Widget

Mathematical Program in JAVA

 1. Calculate the Area of Circle


import java.util.Scanner;
class AreaOfCircle 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the radius:");
         double r= s.nextDouble();
         double  area=(22*r*r)/7 ;
         System.out.println("Area of Circle is: " + area);      
   }
}


Output :-


Enter the radius:
25
Area of Circle is: 1964.2857142857142



2. Calculate the Area of Triangle


import java.util.Scanner;
class AreaOfTriangle 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the width of the Triangle:");
         double b= s.nextDouble();
 
         System.out.println("Enter the height of the Triangle:");
          double h= s.nextDouble();
 
                  //Area = (width*height)/2
      double area=(b*h)/2;
      System.out.println("Area of Triangle is: " + area);      
   }
}


Output :-


Enter the width of the Triangle:25
Enter the height of the Triangle:
25
Area of Triangle is: 312.5



3. Calculate the Area of Rectangle


import java.util.Scanner;
class AreaOfRectangle 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the length:");
         double l= s.nextDouble();
        System.out.println("Enter the breadth:");
         double b= s.nextDouble();
        
          
          double  area=l*b;
      System.out.println("Area of Rectangle is: " + area);      
   }
}


Output :-



Enter the length:
30
Enter the breadth:
20
Area of Rectangle is: 600.0



4. Calculate the Area of Isosceles Triangle


import java.util.Scanner;
class AreaOfIsoscelesTriangle 
{
   public static void main(String args[]) 
    {   
       
         Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the length of same sided :");
         
         double a= s.nextDouble();
         
         System.out.println("Enter the side2 of the Triangle :");
         
         double b= s.nextDouble();
 
         double  area=(b/4)*Math.sqrt((4*a*a)-(b*b));
      
         System.out.println("Area of Isosceles Triangle is: " + area);
   }
}


Output :-



Enter the length of same sided :25
Enter the side2 of the Triangle :
20
Area of Isosceles Triangle is: 229.128784747792



5. Calculate the Area of Equilateral Triangle



import java.util.Scanner;
class AreaOfEquilateralTriangle 
{
   public static void main(String args[]) 
    {   
       
          Scanner s= new Scanner(System.in);
          System.out.println("Enter the side of the Triangle:");
          double a= s.nextDouble();
          double  area=(Math.sqrt(3)/4)*(a*a);
          System.out.println("Area of Triangle is: " + area);      
     }
}


Output :-


 


Enter the side of the Triangle:
25
Area of Triangle is: 270.6329386826371



6. Calculate the Area of Rhombus


import java.util.Scanner;
class AreaOfRhombus 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the diagonal 1:");
         double d1= s.nextDouble();
        System.out.println("Enter the diagonal 2:");
         double d2= s.nextDouble();
          
          double  area=(d1*d2)/2;
      System.out.println("Area of Rhombus is: " + area);      
   }
}


Output :-



Enter the diagonal 1:
25
Enter the diagonal 2:
30
Area of Rhombus is: 375.0



7. Perimeter of the Circle


import java.util.Scanner;
class PerimeterOfCircle 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the radius:");
         
double r= s.nextDouble();
         
double  c=(22*2*r)/7 ;
      
System.out.println("Perimeter of Circle is: " +c);      
   }
}


Output :-



Enter the radius:25
Perimeter of Circle is: 157.14285714285714



8. Perimeter of the Square



import java.util.Scanner;
class PerimeterOfSquare
{
   public static void main(String args[]) 
    {   
       
         Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the side of the square:");
         
double a= s.nextDouble();
 
         double  perimeter=4*a;
     
System.out.println("perimeter of Square is: " + perimeter);      
   }
}


Output :-



Enter the side of the square : 25
perimeter of Square is: 100



9. Perimeter of the Rectangle


import java.util.Scanner;
class PerimeterOfRectangle
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the length of the Rectangle:");
         
double l= s.nextDouble();
 
System.out.println("Enter the width of the Rectangle:");
         
double b= s.nextDouble();
          
         double  perimeter=2*(l+b);
      
System.out.println("perimeter of Rectangle is: " + perimeter);      
   }
}


Output :-



Enter the length of the Rectangle:25 
Enter the width of the Rectangle:30
perimeter of Rectangle is: 110.0



10. Perimeter of the Equilateral Triangle



import java.util.Scanner;
class PerimeterOfEquilateralTriangle 
{
   public static void main(String args[]) 
    {   
       
         Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the side of the Triangle:");
         
double a= s.nextDouble();
 
         double  perimeter=3*a;
      
         System.out.println("perimeter of Triangle is: " + perimeter);      
   }
}


Output :-



Enter the side of the Triangle:25
perimeter of Triangle is: 75.0



11. Volume of Sphere


import java.util.Scanner;
class VolumeOfSphere 
{
      
   public static void main(String args[]) 
    {   
       
            Scanner s= new Scanner(System.in);
          System.out.println("Enter the radius of sphere:");
          double r=s.nextDouble();
                
       
                 double  volume= (4*22*r*r*r)/(3*7);
 
             System.out.println("Volume is:" +volume);
      }
}


Output :-



Enter the radius of sphere:
25
Volume is:65476.19047619047




12. Volume of Prism


import java.util.Scanner;
class VolumeOfPrism 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the area of base:");
         double base=s.nextDouble();
         System.out.println("Enter the height:");
         double height=s.nextDouble();
         
 
          
          double  area=base*height ;
      System.out.println("Volume Of Prism is: " + area);      
   }
}


Output :-



Enter the area of base:
25
Enter the height:
25
Volume Of Prism is: 625.0



13. Volume of Cylinder


import java.util.Scanner;
class VolumeOfCylinder 
{
   public static void main(String args[]) 
    {   
       
      Scanner s= new Scanner(System.in);
        
         System.out.println("Enter the radius:");
         double r=s.nextDouble();
         System.out.println("Enter the height:");
         double h=s.nextDouble();
 
            double  volume=((22*r*r*h)/7);
 
            System.out.println("volume of Cylinder is: " +volume);
   }
}


Output :-



Enter the radius:
25
Enter the height:
25
volume of Cylinder is: 49107.142857142855





 





Post a Comment

0 Comments