Thread: help student
View Single Post
  #12 (permalink)  
Old 01-29-2008, 11:51 PM
jvasilj1 jvasilj1 is offline
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
this is now my code and it is giving me 4 errors. the errors are
--------------------------------------------------------------
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:17: cannot find symbol
symbol : variable next
location: class java.util.Scanner
orig = con.next;
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:20: incompatible types
found : char
required: java.lang.String
letter = orig.charAt(i);
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:21: cannot find symbol
symbol : method isLetter(java.lang.String)
location: class java.lang.Character
if (Character.isLetter(letter))
^
C:\Documents and Settings\dpuser\My Documents\PalindromeCheck.java:22: cannot find symbol
symbol : method toUpperCase()
location: class java.lang.Character
processed += Character.toUpperCase( );
^
4 errors

Tool completed with exit code 1
---------------------------------------------

this is my code
-------------------------------------
// Check to see if an input string is a palindrome
// orig is the original string,
// processed is the string after removing all characters
// that are not letters and converting to upper case.

import java.util.Scanner;

public class PalindromeCheck
{
private static void main(String argv)
{
String orig, processed, letter;
int left, right;
Scanner con = new Scanner(System.in);

System.out.println("Enter a string:");
orig = con.next;
for(int i = 0; i < orig.length( ); i++)
{
letter = orig.charAt(i);
if (Character.isLetter(letter))
processed += Character.toUpperCase( );
}

if (processed.length( ) < 0);
{
left = 0;
right = processed.length( );
while (left < right)
{
if (processed.charAt(left) != processed.charAt(right))
System.out.println("String is not a palindrome.");
else
System.out.println("String is a palindrome.");

left++;
right--;
}
System.out.println("String is a palindrome.");
}

}
}
Reply With Quote