Showing posts with label Series Programs. Show all posts
Showing posts with label Series Programs. Show all posts

Tuesday, January 30, 2024

Java Program Pell Number Series

 What is the Pell series?

Pell series starts with the first term as 0 and the second term as 1. The next term will be an addition to the second last term and two times to the last term. Now, if we compute the third term it will be the sum of the second last term (0), and twice of the last term (21) is 2 (0+2). 

The fourth term will be the sum of the second last term (1) and twice of the last term (22) is 5 (1+4).

 We can find more terms using the same method.

Relation of Pell series number: T(n) = T(n-2) + 2T(n-1)

T(1) = 0

T(2) = 1

T(3) = 0+2*1 = 0+2 = 2

T(4) = 1+2*2 = 1+4 = 5

T(5) = 2+2*5 = 2+10 = 12

.

.

.

T(n) = T(n-2) + 2*T(n-1)

import java.util.*;

class Pell

{

   Scanner sc=new Scanner(System.in);

    void main()

    {

       int i,n,a=0,b=1,next; 

       System.out.print("\nHow many Elements:");

       n=sc.nextInt();

         System.out.print("Series as follows "+a+" "+b);  

       for(i=0;i<n-2;i++)

       {

           next=a+2*b;           

           System.out.print(" "+next);

           a=b;

           b=next;

        }     

    }

Java Program Triangular Number Series

 The first 10 terms of the Triangular number series:

1 3 6 10 15 21 28 36 45 55 


class Triangular

{ 

    void main()

    {      

         int i,n=1;          

         System.out.println("Series as follows ");  

       for(i=0;i<10;i++)

       {

           n=n+i;

           System.out.print(" "+n);

           n++;

        }     

    }

}  

Tuesday, December 6, 2022

Function Overloading Programs on Series

 Design a class to overload a function series() as follows:


(a) void series(int x, int n): to display the sum of the series given below:

x1 + x2 + x3 + … + xn terms


(b) void series(int p): to display the following series:

0, 7, 26, 63, … p terms.


(c) void series(): to display the sum of the series given below:

1/2 + 1/3 + 1/4 + … + 1/10.


Program on Function  Overloading To Display Series

public class Series
{
 
    public void series(int x, int n)
    {
        double sum = 0L;
        for(int i = 1; i <= n; i++)
        {
            sum=sum+Math.pow(x, i);
        }
        System.out.println("Sum of series is (1st Overloaded function)" + sum);
    }
    public void series(int p)
    {
        int term=0;
        System.out.print("\n2nd Overloaded function ");
        for(int i = 1; i <= p; i++)
        {
            term = (int)(Math.pow(i, 3)-1);
            System.out.print(term + " ");
        }
    }
    public void series()
    {
        double sum = 0.0;
        for(int i = 2; i <= 10; i++)
            sum = sum+ 1.0 / i;
        System.out.println("\n\nSum of series is (3rd Overloaded function)" + sum);
    }
    
    public static void main(String args[])
    {
      Series ob = new Series();
      ob.series(2,4);
      ob.series(6);
      ob.series();  
    } 
  
}

Back To BlueJ Series Display Programs Home Page: CLICK HERE

Friday, December 11, 2020

List Of Java Series Display Programs For ICSE And ISC Students

Series display programs using Java language for ICSE and ISC students are posted here. The programs can be executed on BlueJ or any other editors. Here you will get links to number of programs along with explanation. Hope it will help students.

To view the BlueJ Series programs, click on the links



Fibonacci Series

Pell Number Series

Series 1-2/2!+3/3!-4/4! + ...+ n/n!

Series (1*2)+(2*3)+......+(19*20)

BlueJ Program to find whether a number is in Fibonacci series or not

Series 0,3,8,15,24

Series 3,33,333,3333,33333,333333,3333333,33333333

Fibonacci numbers Using Recursive Function and its Algorithm

Series x/2!+x/4!+x/6!+....n terms

Series 1+2/1*2 + 1+2+3/1*2*3 + ....+ 1+2+3+..+n/1*2*3*...*n 

BlueJ Program on Tribonacci Series Display



  






To Get More Programs:


ISC Practical Papers With Solution

ISC Theoretical Papers With Solution 

ICSE Theoretical Papers With Solution 

Saturday, August 31, 2019

Display Sum of Series: 1 + (1+2) / (1*2) + (1+2+3) / (1*2*3) + ….. + (1+2+3+…+n) / (1*2*3*…*n)

This is a BlueJ Program which displays sum of a series using nested loop.



import java.util.*;
class Max
{
Scanner sc=new Scanner(System.in);
int n,i,j;
double sum=0;
int s,p;
public void take()
{
System.out.print("\nValue of 'n': ");
n=sc.nextInt();



for(i=1;i< =n;i++)
{
    s=0;
    p=1;
  for(j=1;j< =i;j++)
  {
      s=s+j;
      p=p*j;
    }
    sum=sum + (double)s/p; 
}
System.out.println("\nSum of the series: "+sum);
}
public static void main(String args[])
{
Max ob=new Max();
ob.take();
}
}


Back To BlueJ Series Display Programs Home Page: CLICK HERE

BlueJ Program To Display Sum of Series: x – x^3 + x^5 – x^7 + ….. x^n


This is a BlueJ program which displays the sum of a series using pow function of Math class.


import java.util.*;
class Max
{
Scanner sc=new Scanner(System.in);
int n,i,x,c=1;
double sum=0;
public void take()
{
System.out.print("\nValue of 'n': ");


n=sc.nextInt();
System.out.print("\nValue of 'x': ");
x=sc.nextInt();
for(i=1;i< =n;i=i+2)
{
  sum=sum + Math.pow(x,i)*c;
  c=c*-1;
}
System.out.println("\nSum of the series: "+sum);
}
public static void main(String args[])
{
Max ob=new Max();
ob.take();
}
}


Back To BlueJ Series Display Programs Home Page: CLICK HERE

Display sum of the series x!/10 + (x+2)!/15 + (x+4)!/20 + (x+n)!/100

Series program using BlueJ where a separate function is used to calculate factorial value.

The series is x!/10 + (x+2)!/15 + (x+4)!/20 + (x+n)!/100

import java.util.*;
class Search
{
    int x,c=10,n;
    double sum=0;
    int j=10;
    Scanner sc=new Scanner(System.in);
public void assign()
{   
System.out.print("\nEnter value of 'x': ");
x=sc.nextInt();
System.out.print("\nEnter value of 'n':");


n=sc.nextInt();
}
public void display()
{
    for(int i=0;i< =n;i=i+2)
    {
         sum=sum + fact(x+i)/(double)j;
    }
    System.out.println("\nSum of the series: "+sum);
}
 public int fact(int n)
 {
      int i,f=1;
      for(i=1;i< =n;i++)
      {
           f=f*i;
        }
        return f;
    }     
    public static void main(String args[])
    {
        Search ob=new Search();
        ob.assign();
        ob.display();
   }
 }


Back To BlueJ Series Display Programs Home Page: CLICK HERE

Display sum of the series 1/(1+2) + 1/(1+2+3) + 1/(1+2+3+4) + …. n terms


This is a BlueJ Program on series. This program involves nested loop.



import java.util.*;
class Search
{
    int i,j;
    double sum=0;
    int x,n;
    Scanner sc=new Scanner(System.in);
public void display()
{
     System.out.print("\nEnter Value of 'n': ");
     n=sc.nextInt();
    for(int i=0;i< n;i++)
    {
        x=0;
       for(j=1;j< =i+2;j++)
      
       {
           x=x+j;
       }


       sum=sum + 1.0/x;
    }
    System.out.println("\nSum of the series: "+sum);
}
      
    public static void main(String args[])
    {
        Search ob=new Search();
        ob.display();
   }
 }


Back To BlueJ Series Display Programs Home Page: CLICK HERE

Display the series 2 + 4/2! + 8/3! + 16/4! + …..+ 2^n/n!


This is a series program using BlueJ. Here 2,4,8 are 21,  22, 23



Write this program using

n: stores the number of terms
s: double type variable to store sum of series

Exponent value is 2

import java.util.*;
class Search
{
    long n;
    double s;
    Scanner sc=new Scanner(System.in);
public void assign()
{   
System.out.print("\nEnter the values of 'n':");


n=sc.nextLong();
}
public void display()
{
    for(long i=1;i< =n;i++)
    {
         s=s+Math.pow(2,i)/fact(i);
    }
    System.out.print("\nSum of the series = " + s);
  
}
public long fact(long x)
{
     long f=1;
for(long i=1;i< =x;i++)
f=f*i;
return f;
}
    public static void main(String args[])
    {
        Search ob=new Search();
        ob.assign();
        ob.display();
   }
 }


Back To BlueJ Series Display Programs Home Page: CLICK HERE

Sunday, August 18, 2019

BlueJ Program To Display Sum of The Series s=x^2 - x^4/3! + x^6/5!-.... n terms


BlueJ Program on Sum of The Series s=x^2 -  x^4/3! + x^6/5!-.... n terms.



import java.util.*;
public class Series
{
    Scanner sc=new Scanner(System.in);
    int s=0,n,i,j,x,c=1;
    public void firstSeries()
    {
         
          System.out.print("\nEnter the value of 'n':");
         n=sc.nextInt();
         System.out.print("\nEnter the value of 'x':");
         x=sc.nextInt();
         for(i=2;i<=n;i=i+2)


         {
              s=s+(int)(Math.pow(x,i)*c/fact(i-1));
              c=c*-1;
            }
           
            System.out.print("Sum of the series x^2 - x^4/3! + x^6/5!-.... n term:"+s);
           
            }
            private int fact(int n)
            {
                 int f=1;
                 for(j=1;j<=n;j++)
                 {
                     f=f*j;
                    }
                    return f;
                }
                  
            public static void main(String args[])
            {
                 Series obj=new Series ();
                 obj.firstSeries();
                }
            }


Back To BlueJ Series Display Programs Home Page: CLICK HERE

BlueJ Program To Display Sum of The Series s=1+(1+2+3)+ (1+2+3+4+5)+... n terms


BlueJ Program on sum of series like 1+(1+2+3)+ (1+2+3+4+5)+... n terms.



import java.util.*;
public class Series1
{
    Scanner sc=new Scanner(System.in);
    int s=0,n,i,j;

    public void secondSeries()
    {
          System.out.print("\nEnter the value of 'n':");
         n=sc.nextInt();
         s=0;
         for(i=1;i<=n;i=i+2)
         {
              for(j=1;j<=i;j++)
              {
                   s=s+j;
                }
            }
            System.out.print("Sum of the series 1+(1+2+3)+ (1+2+3+4+5)+... n terms.... n term:"+s);
            }
                  
            public static void main(String args[])


            {
                 Series1 obj=new Series1 ();
                 obj.secondSeries();
              }
            }


Related Post: BlueJ Programs on Series

Thursday, November 19, 2015

Print a series of values divided by its factorial values


Show the sum of the series: 1-2/2!+3/3!-4/4! + ...+ n/n!



import java.io.*;
class Num
{
int i,n;
double sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take () throws Exception
 {
    System.out.println("Take the value of 'n':");
    n=Integer.parseInt(br.readLine());
    for( i=1;i<=n;i++)
    {
   if(i%2==0)
   sum=sum-(double)i/fact(i);
   else
   sum=sum+(double)i/fact(i);
   }
    System.out.println("Sum of the series="+sum);
    }

    private int fact(int x)
    {
     int f=1;
     for(int j=2;j<=x;j++)
     f=f*j;
     return f;
     }
   public static void main(String args[]) throws Exception
   {
    Num object=new Num();
    object.take();
    }
    }

Back To BlueJ Series Display Programs Home Page: CLICK HERE

Tuesday, December 30, 2014

BlueJ Program to print the series (1*2)+(2*3)+......+(19*20)


Here is the BlueJ program.




class S
{
  
   int i;
   long lg=0;
    public void show()
    {
        for(i=1;i< 20;i++)
        {
            lg=lg+(i*(i+1));
        }
        System.out.println("Series="+lg);
    }
        public static void main(String args[])
        {
             S ob=new S();
             ob.show();
            }

        }

Back To BlueJ Series Display Programs Home Page: CLICK HERE

Tuesday, February 14, 2012

BlueJ Program on Pythagorean triplets Display


Pythagorean triplet consists of three positive integers namely a,b and c in such a way that a2 + b2 = c2. Some examples of Pythagorean triplets are :

( 3 , 4 , 5 )
( 5, 12, 13)
( 7, 24, 25)
( 8, 15, 17)
( 9, 40, 41)
(11, 60, 61)
(12, 35, 37)
(13, 84, 85)
(16, 63, 65)
(20, 21, 29)
(28, 45, 53)
(33, 56, 65)
(36, 77, 85)
(39, 80, 89)
(48, 55, 73)
(65, 72, 97)

 Here is the bluej program where the Pythagorean triplets staring from 1 to 50 are displayed.

class Max
{
int i,j,k,a,b,c,m=50;
public void disp()
{
System.out.println("The Pythogorean triplets are");
for(i=1;i< m-2;i++)
{
for(j=i+1;j< m-1;j++)
{
 for(k=j+1;k< m;k++)
 {
a=i;
b=j;
c=k;
if(a*a+b*b==c*c)
System.out.println("("+a+ ","+b+","+c+")");
}
}
}
}
public static void main(String args[])
{
 Max ob=new Max();
 ob.disp();
}
}

Sample output:

The Pythogorean triplets are
(3,4,5)
(5,12,13)
(6,8,10)
(7,24,25)
(8,15,17)
(9,12,15)
(9,40,41)
(10,24,26)
(12,16,20)
(12,35,37)
(15,20,25)
(15,36,39)
(16,30,34)
(18,24,30)
(20,21,29)
(21,28,35)
(24,32,40)
(27,36,45)


Back To BlueJ Series Display Programs Home Page: CLICK HERE

BlueJ Program on Tribonacci Series Display


Tribonacci series is like Fibonacci series with slight difference. In this series the latest three numbers are added and the result is displayed.

import java.io.*;
class Max
{
int i,p,m,c,next,n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void disp()throws Exception
{
p=0;
m=1;
c=1;
System.out.println("Enter the number of elements in the series:");
n=Integer.parseInt(br.readLine());
System.out.print("The series is="+ p+" "+m+" "+c+ " ");
for(i=0;i< n-3;i++)
{
next=p+m+c;
System.out.print(next+ " ");
p=m;
m=c;
c=next;
}
}
public static void main(String args[])throws Exception
{
 Max ob=new Max();
 ob.disp();
}
}


Back To BlueJ Series Display Programs Home Page: CLICK HERE

Subscribe via email

Enter your email address:

Delivered by FeedBurner