Computer Science, asked by shrujana1630, 1 year ago

write a menu driven program to accept a no do the fpllowing operation based on selection
1) palindrome no
2)fibonacci series
3)find the factorial of given no using recursion

Answers

Answered by shardul1925
5
Hello

1)

Palindrome Number--

import java.util.Scanner;

class Palindrome{
public static void main(String args[]){
System.out.print("Enter Number: ");
Scanner read = new Scanner(System.in);
int num = read.nextInt();
int n = num;

//reversing number
int rev=0,rmd;
while(num > 0)
{
rmd = num % 10;
rev = rev * 10 + rmd;
num = num / 10;
}

if(rev == n)
System.out.println(n+" is a Palindrome Number!");
else
System.out.println(n+" is not a Palindrome Number!");
}
}

Output--Enter Number:
552255


552255 is a Palindrome Number!



3)



Factorial using recursion

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Factorial {

public static void main(String args[]) throws NumberFormatException, IOException{

System.out.println("Enter an integer to calculate it's factorial ");

//get input from the user
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a = Integer.parseInt(br.readLine());

//call the recursive function to generate factorial
int result= fact(a);


System.out.println("Factorial of "+a+" is = " + result);
}

static int fact(int b)
{
if(b <= 1)
//if the number is 1 then return 1
return 1;
else
//else call the same function with the value - 1
return b * fact(b-1);
}
}

Output--Enter an integer to calculate it's Factorial
6
Factorial of 6 is = 720


Note:Can u tell me what is fibonacci series so that I can write a program on it.



nitish8089: ya ! if you in ICSE you can use switch for this...
shardul1925: yaa..it is in my book..of class 9 icse
nitish8089: yes but i am not in 9th...
nitish8089: :)
nitish8089: so i don't know i used it or some thing orher for this but helpful
nitish8089: *other
nitish8089: if you make yourself all program then it's really an awesome....
nitish8089: use java librarary awesome code
shardul1925: hmm..thxx..for it
Prakhar2908: Gr8 answer !
Similar questions