Java program to check the given string is palindrome or not without using Reverse String

Simple Java program to check the given string is palindrome or not without using Reverse String

Code:

import java.util.Scanner;

class p84{public static void main(String args[]){

Scanner sc = new Scanner(System.in);

String s = sc.nextLine();

boolean palindrome=true;

int j=(s.length()-1);

for(int i=0;i<(s.length()/2);i++){

if(s.charAt(i)!=s.charAt(j)){palindrome=false;}

j--;

}

if(palindrome){System.out.println("palindrome");}

else{System.out.println("Not palindrome");}

}}

Comments

Popular posts from this blog

C program to implement Circular Linked List

C++ program to perform data transformation Min-max and Z score Normalization

Java program to implement Word Count using Map-Reduce in Hadoop Cluster