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
Post a Comment