Advertisement
Huntersazzad

lab5_task2

Oct 29th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. package lab5;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class task2 {
  6.     public static  boolean isPalidrome(String arg) {
  7.         int lenth =arg.length();
  8.         int n=0;
  9.         for(int i=0; i<lenth/2;i++) {
  10.             if(arg.charAt(i)==arg.charAt((lenth-1)-i))
  11.                  n=1;
  12.             }
  13.         if(n==1)
  14.             return true;
  15.         else
  16.         return false;
  17.        
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.       Scanner ac = new Scanner(System.in);
  22.       System.out.println("enter any word");
  23.       String word=ac.nextLine();
  24.       if(isPalidrome(word)) {
  25.           System.out.println( word+ "  is Palidrome");
  26.       }
  27.       else
  28.           System.out.println( word+ " is not Palidrome");
  29.          
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement