'double' data type

As you have seen that assigning decimal values to the integer variable is resulting in an error in our previous post. So we have to declare the variable with the data type that allows us to assign decimal values to the variables. This is possible only by declaring the variables using 'double' data type.




The following program will demonstrate the 'double' data type:

class Sample
{
     public static void main(String args[])
     {
         double count = 100.123;
         System.out.println(count);
      }
 }

Output of this program:

100.123




Program to compute the area of the circle using 'double' data type

class Area
{
  public static void main(String args[])
  {
     double pi,r,a;
 
     r = 10.8;   //Radius of the circle
     pi = 3.1416;   //Approximate Pi value
     a = pi*r*r;   //Compute area of the circle
 
     System.out.println("Area of the circle is " + a);
   }
 }

Output of this program:

Area of the circle is 366.436224