Write a function for palindrome and factorial and explain?



Write a function for palindrome and factorial and explain?..

Answer / Manish Kumar Gupt

A Palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward.nFor example: 'racecar' and '12321'.nnIn Java, you can write a function to check if a string is palindrome like this:n```javanpublic boolean isPalindrome(String s) {n String reversed = new StringBuilder(s).reverse().toString();n return s.equalsIgnoreCase(reversed);n}nFor the factorial function, it calculates the product of all positive integers up to a given number:n```javanpublic int factorial(int n) {n if (n == 0) return 1;n return n * factorial(n - 1);n}nFactorial function has time complexity O(n).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Who developed JScript language?

3 Answers  


what is the difference between ArrayList and Vector

19 Answers   KPIT, Sasken, Satyam, Span Infotech, Wipro,


What is unicode?

5 Answers  


Is java free for commercial?

1 Answers  


What is object cloning in Java?

1 Answers   SwanSoft Technologies,


What are the actions that can occur when a thread enters blocked state?

1 Answers  


What is immutable state?

1 Answers  


Which containers use a FlowLayout as their default layout?

3 Answers  


What is reverse function?

1 Answers  


What is matcher in java?

1 Answers  


Why does java have different data types for integers and floating-point values?

1 Answers  


Which oo concept is achieved by using overloading and overriding?

1 Answers  


Categories