Skip to main content

Posts

Showing posts with the label reverse

Write a program to reverse a number

 Java Python

Check a string is palindrome or not

 A string is said to be a  palindrome if the string remains the same after reversing. eg.-  - code (after reversing the string " code " it becomes " edoc ")  so, the given string " code " is not a palindrome. - madam (after reversing the string  " madam " it becomes " madam ")  so, the given string " madam " is a palindrome. Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.Scanner; public class CheckStringPalindrome { public static void main (String[] args) { Scanner sc = new Scanner(System. in ); String str = sc. nextLine (); StringBuffer sb = new StringBuffer(str); sb. reverse (); String rev = new String(sb); if (str. equals (rev)) { System. out . println ( "String is Palindrome" ); ...