Binomial Series in Java 1+1/x+1/x2+1/x3...

Code Of Binomial Series in Java  1+1/x+1/x2+1/x3...

Code:

package sereies;

import java.util.Scanner;



class Sereies
{
      public static void main(String ar[])
      {
    double i,x=0,n=0,sum=1;
   
            Scanner obj= new Scanner(System.in);

            try
            {

                  System.out.println("Enter the value of x:");
                  x=obj.nextInt();
                  System.out.println("Enter the value of n:");
                  n=obj.nextInt();
            }

            catch(Exception e)
            {
            }
            for(i=0;i<=n;i++)
            { sum=sum+1/Math.pow(x,i);}
            System.out.println("Sum is: "+sum);
      }
}

   

OutPut: 

Enter the value of x:
5
Enter the value of n:
4
Sum is: 2.2496 


Code Of Binomial Series in Java  1+1/x+1/x2+1/x3...
 

Comments

Popular posts from this blog

GUI in Java | How to make userdefined login page in graphical user interface in java

Multiple Inheritence in Java /How to inherit a class from another in Java| Programmer Hub

Update a value on specific index in Array List | Programming Hub 0