Advertisement
G_Burlakova

Palindrome

Nov 25th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package palindrome;
  8.  
  9. /**
  10.  *
  11.  * @author Gaby
  12.  */
  13. import java.util.Scanner;
  14. public class Palindrome {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static void main(String[] args) {
  20.         Scanner imput = new Scanner(System.in);
  21.         System.out.println("Enter your word");
  22.         String word = imput.next();
  23.         boolean a = true;
  24.             for ( int i = 0; i < word.length(); i++) {
  25.                 if (word.charAt(i) != word.charAt(word.length() - i - 1)){
  26.                     a = false; break;
  27.                 } else{
  28.                     a = true;
  29.                 }
  30.             }
  31.             if (a == true){
  32.                 System.out.println("The word " + word + " is a palindrome");
  33.                
  34.             } else{
  35.                 System.out.println("The word " + word + " is not a palindrome");
  36.             }
  37.     }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement