Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class palin
  4. {
  5.     public static void main ( String args[] )
  6.     {
  7.         Scanner input = new Scanner ( System.in );
  8.  
  9.  
  10.         String word;
  11.         String arr;
  12.         String arr2;
  13.         int count;
  14.  
  15.         //prompt for word and set word to word
  16.         System.out.print ( "word: " );
  17.         word = input.next();
  18.  
  19.         //set count to word length
  20.         count = word.length() - 1;
  21.  
  22.         //set the word equal to two dummy vars
  23.         arr = arr2 = word;
  24.  
  25.         //loop as large as word
  26.         for ( int i = 0; i < count; ++i )
  27.         {
  28.             //if one char isn't equal to another, break
  29.             if ( arr.charAt(i) != arr2.charAt(count--) )
  30.             {
  31.                 System.out.println ( "not palin bro" );
  32.                 break;
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement