I need some help with this Java code. It's supposed to be a code that says if a text is a palindrom or not (I have no idea what's its called in english). A palindrom is a text that will be spelled the same if it's read backwards (=adolf i paris rapar sirap i floda).
This is the start code:
I am only allowed to add new code in the main-method:
I've already added a Scanner to the code. It now loks like this:
If you think you can help me please post!
I have problem with knowing how to delete all the signs that is not letters in the text I write.
And Im a little unsure how to use the method "nextLine" in the Scanner-class.
This is the start code:
Code:
package your_username;
public class Step3_Lab02
{
public static void main(String[] args)
{
}
}
class Palindrome
{
public boolean isPalindrome(String str)
{
String reverseStr = (new StringBuffer(str)).reverse().toString();
return str.equalsIgnoreCase(reverseStr);
}
public String removeNoneLetters(String str)
{
String result = "";
for (int i = 0; i < str.length(); ++i)
{
if (Character.isLetter(str.charAt(i)))
{
result = result + str.charAt(i);
}
}
return result;
}
}
I am only allowed to add new code in the main-method:
Code:
public static void main(String[] args)
{
}
I've already added a Scanner to the code. It now loks like this:
Code:
package your_username;
import java.util.Scanner;
public class Step3_lab02
{
}
class Palindrome
{
public boolean isPalindrome(String str)
{
String reverseStr = (new StringBuffer(str)).reverse().toString();
return str.equalsIgnoreCase(reverseStr);
}
public String removeNoneLetters(String str)
{
String result = "";
for (int i = 0; i < str.length(); ++i)
{
if (Character.isLetter(str.charAt(i)))
{
result = result + str.charAt(i);
}
}
return result;
}
}
If you think you can help me please post!
I have problem with knowing how to delete all the signs that is not letters in the text I write.
And Im a little unsure how to use the method "nextLine" in the Scanner-class.







