Md_Sakib_Hossain

Pell & Locus Number :)

Feb 28th, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.*;
  2. public class PellAndBell{
  3.     static Scanner scan = new Scanner(System.in);
  4.     public static int pell(int n)
  5.     {
  6.         if (n <= 2)
  7.             return n;
  8.         return 2 * pell(n - 1) + pell(n - 2);
  9.     }
  10.    public static int locus(int b){
  11.      if(b==0)
  12.         return 0;
  13.      else if(b==1)
  14.         return 1;
  15.      else
  16.         return locus(b-1)+locus(b-2);    
  17.    }
  18.  
  19.    public static int SwitchOperation(int n){
  20.     switch (n) {
  21.         case 1: System.out.print("Enter pell number: ");
  22.                 int p=scan.nextInt();
  23.                 System.out.println("Pell number is: "+pell(p));
  24.                 break;
  25.         case 2: System.out.println("Enter locus number: ");
  26.                 int b=scan.nextInt();
  27.                 System.out.println("Bell number is: "+locus(b));
  28.                 break;
  29.         default:
  30.             System.out.println("No operation to perform");
  31.  
  32.     }
  33.     return 0;
  34.    }
  35.  
  36.     public static void main(String[] args) {
  37.         int n;
  38.         System.out.println("Enter operation you want:\n1. Pell number\n2. locus number");
  39.         n=scan.nextInt();
  40.         SwitchOperation(n);
  41.     }
  42. }
Add Comment
Please, Sign In to add comment