Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class PellAndBell{
- static Scanner scan = new Scanner(System.in);
- public static int pell(int n)
- {
- if (n <= 2)
- return n;
- return 2 * pell(n - 1) + pell(n - 2);
- }
- public static int locus(int b){
- if(b==0)
- return 0;
- else if(b==1)
- return 1;
- else
- return locus(b-1)+locus(b-2);
- }
- public static int SwitchOperation(int n){
- switch (n) {
- case 1: System.out.print("Enter pell number: ");
- int p=scan.nextInt();
- System.out.println("Pell number is: "+pell(p));
- break;
- case 2: System.out.println("Enter locus number: ");
- int b=scan.nextInt();
- System.out.println("Bell number is: "+locus(b));
- break;
- default:
- System.out.println("No operation to perform");
- }
- return 0;
- }
- public static void main(String[] args) {
- int n;
- System.out.println("Enter operation you want:\n1. Pell number\n2. locus number");
- n=scan.nextInt();
- SwitchOperation(n);
- }
- }
Add Comment
Please, Sign In to add comment