Question

Implement a recursive algorithm (implemented in Java) that checks if a number is identical when read...

Implement a recursive algorithm (implemented in Java) that checks if a number is identical when read both forwards and backwards

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// Recursive Java program to check if a number is identical when read both forwards and backwards

import java.util.*; 
import java.io.*; 
  class Identical 
{ 
  
// A recursive function to return the reverse of digits of the number
static int reverse(int num, int temp) 
{ 
    // base case 
    if (num == 0) 
        return temp; 
  
    // to store the reverse  of a number 
    temp = (temp * 10) + (num % 10); 
  
    return reverse(num/ 10, temp); 
} 
  
// Driver Code 
 public static void main(String args[])   
{ 
      int num = 0; 
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the number");
      num = sc.nextInt();
    int temp = reverse(num, 0); 
      
    if (temp == num) 
    System.out.println("Yes, the number is identical when read both forwards and backwards"); 
    else
    System.out.println("No, the number is not identical when read both forwards and backwards" ); 
} //main()
} //class
  
Add a comment
Know the answer?
Add Answer to:
Implement a recursive algorithm (implemented in Java) that checks if a number is identical when read...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT