All pastes #748712 Raw Edit

Anonymous

public text v1 · immutable
#748712 ·published 2007-10-25 01:36 UTC
rendered paste body
//COSC 24430.001
//Project 3
//Alison Gravley
//Due 9/27/07
//Description: Program will ask user to input a sentence and it will tell them if its a palindrome or not.

import java.util.Scanner;

public class Palindrome
{
	
	public static void main(String[] args)
	{
		int program = 1;
		while(program == 1) //beginning of loop
		{
		String phrase;
		System.out.println("Please enter a sentence ending with a period.");
		Scanner input = new Scanner(System.in);
		phrase = input.nextLine();
		String newPhrase = phrase.replace( " ", "");
		String finalPhrase = newPhrase.replace(".","");
		
		
		if(palindrome(finalPhrase))
			System.out.println("YES, the phrase is a palindrome!");
		else
			System.out.println("NO, the phrase is NOT a palindrome.");
		
	System.out.println("Want to do another? 1 for yes, 2 for no.");
	program = input.nextInt();
		}
	}
	public static boolean palindrome(String text)
	{
		int length = text.length();
		boolean result = true;
		for(int i=0;i<length;i++)
		{
			
			char beginning, end;
			beginning = text.charAt(i);
			end = text.charAt(length-1);
			length--;
			if (beginning != end)
			{
				result= false;
			}
		}
		return(result);
	}
	}