chowdhury_riham

Palindrome-checks Letters and numbers, ignores other signs

Sep 30th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4. public class palindrome {
  5.     public static void main(String[] args) {
  6.         System.out.println("No of Inputs:");
  7.         Scanner sc=new Scanner(System.in);
  8.         int noIn=sc.nextInt();
  9.         System.out.println("Enter the Inputs");
  10.         String[] inSt= new String[noIn];
  11.         String [] result=new String[noIn];
  12.         String temp=sc.nextLine();
  13.         for(int i=0;i<noIn;i++){
  14.            inSt[i]=sc.nextLine().toUpperCase();
  15.            char[] inCh =inSt[i].toCharArray();
  16.            result[i]=istPalindrom(inCh);
  17.            
  18.         }
  19.         for(String i:result){
  20.        
  21.         System.out.print(i+"\t");
  22.         }
  23.         System.out.println();
  24.     }
  25.  
  26.     public static String istPalindrom(char[] wort){
  27.         int k=0;
  28.         for(int j=0;j<wort.length;j++){
  29.             if((int)wort[j]>64&& (int)wort[j]<91||(int)wort[j]>47&& (int)wort[j]<58){
  30.                 wort[k]=wort[j];
  31.                 k++;
  32.             }
  33.         }
  34.         String palindrom = "N";
  35.             for(int i = 0; i <=k/2-1; i++){
  36.                
  37.                 if(wort[i] != wort[k-i-1]){
  38.                    palindrom="N";
  39.                 }else{
  40.                     palindrom = "Y";
  41.                 }
  42.             }
  43.        
  44.         return palindrom;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment