Q7-CW2-friday

mail@pastecode.io avatar
unknown
java
a year ago
758 B
3
Indexable
Never
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("enter your string:");
        String sentences = input.nextLine();
        String reverse = stringReverse(sentences);
        if (sentences.equalsIgnoreCase(reverse))
            System.out.println("given string is a palindrome");
        else
            System.out.println("given string is not a palindrome");
    }
    public static String stringReverse(String reverseSentence) {
        String result = "";

        for (int i = reverseSentence.length() - 1; i >= 0; i--) {
            result += reverseSentence.charAt(i);
        }
        return result;
    }
}