Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- * Name: Will Costen
- * PID: 7201-33275
- * Test Plan
- *
- */
- public class Palindrome {
- public static void main(String[] args) {
- {
- String s;
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Please enter a possible palindrome");
- s = keyboard.nextLine();
- int n=s.length();
- String str="";
- String s2="";
- for(int j=0;j<=s.length()-1;j++) //reads string forwards
- if (s.charAt(j)!=' '){
- s2+=s.charAt(j);
- }
- for(int i=n-1;i>=0;i--) //reads string backwards
- if (s.charAt(i)!=' ')
- str=str+s.charAt(i);
- if(str.equalsIgnoreCase(s2)) //confirms palindrome
- System.out.println(s+ " is a palindrome");
- else{
- System.out.println(str);
- System.out.println(s2);
- System.out.println(s+ " is not a palindrome");
- }
- }
- // Java will read the entire line into the variable 'phrase'.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement