Java String Manipulation 28th Jan Practice 2 - input a string and check whether it is a palindrome or not

Palindrome is a number or a string which when reversed is the same as the original. 


Output

import java.util.*;

class Main {

    public static void main(String[] args) {

Scanner in = new Scanner(System.in);

String s,s1=""; char ch;


System.out.println("Enter a String");

s = in.next();

int l = s.length();

s = s.toUpperCase();

for(int i=l-1; i>=0; i--){

    ch = s.charAt(i);

    s1 = s1+ch;

}

System.out.println(s1);

if(s1.equals(s)){

    System.out.println("Palindrome");

    

}

else

System.out.println("Not a palindrome");


    }

}

Comments

Translate

Popular posts from this blog

Letter to SBI Bank Manager of Local Branch to reduce the interest rate on home loan

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Java Recursion Program Practise 1 - Factorial

Java Recursion Program Practise 3 - Raising base to power of index

Java Recursion Program Practise 2 - Fibonacci Series

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Java Recursion Program Practise 4 - to input a number and display sum from 1 to that number

Abhisara - the Tryst Notes

Narrate an experience that shows appearances can be deceiving