Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     /**
  6.     * @param args the command line arguments
  7.     */
  8.     public static void main(String[] args) {
  9.  
  10.         Scanner sc = new Scanner(System.in);
  11.         System.out.println("Podaj 1 wyraz: ");
  12.         String a = sc.nextLine();
  13.         int h = a.length();
  14.  
  15.         int kk = 0;
  16.         int k = (h - 1);
  17.         for (int i = 0; i < h; i++) {
  18.  
  19.             if (a.charAt(i) != a.charAt(k)) {
  20.                 kk = 1;
  21.                 break;
  22.             }
  23.             k--;
  24.         }
  25.  
  26.         if (kk == 1)
  27.             System.out.println("Nie jest palindromem");
  28.         else {
  29.             System.out.println("Jest palindromem");
  30.         }
  31.  
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement