Java String Program

Java Program to check whether a given string is palindrome or not without taking the concept of reverse.

import java.util.*;
class StringPalindrome {

    public static void main(String[] args) {
        String str;
        int l, c = 0;
        Scanner s = new Scanner(System.in);
        System.out.println("enter a string");
        str = s.nextLine();
        l = str.length();
        for (int i = 0; i < (l - 1) / 2; i++) {
            if (str.charAt(i) == str.charAt(l - 1 - i)) {
                continue;
            } else {
                c++;
            }
        }
        if (c == 0)
            System.out.println("the given string is a palindrome");
        else
            System.out.println("the given string is a not palindrome");
    }

Output

pallindrome_program

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

SILAN Technology, BBSR
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment