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 |
Who developed JScript language?
what is the difference between ArrayList and Vector
19 Answers KPIT, Sasken, Satyam, Span Infotech, Wipro,
What is unicode?
Is java free for commercial?
What is object cloning in Java?
1 Answers SwanSoft Technologies,
What are the actions that can occur when a thread enters blocked state?
What is immutable state?
Which containers use a FlowLayout as their default layout?
What is reverse function?
What is matcher in java?
Why does java have different data types for integers and floating-point values?
Which oo concept is achieved by using overloading and overriding?