Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*
  4.  * Implementation Plan
  5.  * 1. Copy the skeleton
  6.  * 2.
  7.  *
  8.  * Test Plan
  9.  *  
  10.  */
  11. public class Palindrome {
  12.  
  13.     public static void main(String[] args) {
  14.          {
  15.              String s;
  16.                 Scanner keyboard = new Scanner(System.in);
  17.  
  18.                 System.out.println("Please enter a possible palindrome");
  19.                 s = keyboard.nextLine();
  20.            
  21.              int i;
  22.  
  23.              int n=s.length();
  24.  
  25.              String str="";
  26.              String s2="";
  27.              
  28.              for(int j=0;j<=s.length()-1;j++)
  29.                  if (s.charAt(j)!=' '){
  30.                      s2+=s.charAt(j);
  31.                    
  32.                  }
  33.  
  34.              for(i=n-1;i>=0;i--)
  35.                  if (s.charAt(i)!=' ')
  36.                      str=str+s.charAt(i);
  37.                
  38.            
  39.                
  40.  
  41.              if(str.equals(s2))
  42.  
  43.                      System.out.println(s+ " is a palindrome");
  44.  
  45.              else
  46.                      System.out.println(str);
  47.                      System.out.println(s2);
  48.                      System.out.println(s+ " is not a palindrome");
  49.  
  50.      }
  51.        
  52.        
  53.     // Java will read the entire line into the variable 'phrase'.
  54.  
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement