Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class palindrome {
- public static void main(String[] args) {
- System.out.println("No of Inputs:");
- Scanner sc=new Scanner(System.in);
- int noIn=sc.nextInt();
- System.out.println("Enter the Inputs");
- String[] inSt= new String[noIn];
- String [] result=new String[noIn];
- String temp=sc.nextLine();
- for(int i=0;i<noIn;i++){
- inSt[i]=sc.nextLine().toUpperCase();
- char[] inCh =inSt[i].toCharArray();
- result[i]=istPalindrom(inCh);
- }
- for(String i:result){
- System.out.print(i+"\t");
- }
- System.out.println();
- }
- public static String istPalindrom(char[] wort){
- int k=0;
- for(int j=0;j<wort.length;j++){
- if((int)wort[j]>64&& (int)wort[j]<91||(int)wort[j]>47&& (int)wort[j]<58){
- wort[k]=wort[j];
- k++;
- }
- }
- String palindrom = "N";
- for(int i = 0; i <=k/2-1; i++){
- if(wort[i] != wort[k-i-1]){
- palindrom="N";
- }else{
- palindrom = "Y";
- }
- }
- return palindrom;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment