Skip to content

Commit

Permalink
Update PalindromeChecker.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Ny09-sand authored Feb 8, 2025
1 parent 015638b commit 8a6803a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/PalindromeChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Scanner; // Import the Scanner class to read text files
public class PalindromeChecker {
public void tester()
public void setup()
{
//String lines[] = loadStrings("palindromes.txt");
String[] lines = new String[6];
Expand All @@ -22,16 +21,22 @@ public void setup()
System.out.println("An error occurred.");
e.printStackTrace();
}
String lines[] = loadStrings("palindromes.txt");
System.out.println("there are " + lines.length + " lines");
for (int i=0; i < lines.length; i++)
{
@@ -37,16 +16,18 @@ public void tester()
if(palindrome(lines[i])==true)
{
System.out.println(lines[i] + " IS a palindrome.");
}
else
{
System.out.println(lines[i] + " is NOT a palindrome.");
}
}
}
public boolean palindrome(String word)
{
//your code here
String no_space= " " ;
String no_space= " " ;
for ( int i = 0 ; i < word.length()-1;i ++){
if (!word.substring(i,i+1).equals(" " )){
no_space+=word.substring(i,i+1);
Expand All @@ -41,7 +46,7 @@ public boolean palindrome(String word)
}
public String reverse(String str)
{
String s = new String("");
String s = new String("");
if (str.length()==0) {return "";}
for ( int i = str.length()-1; i >= 0 ; i --){
if (!str.substring(i,i+1).equals(" " )){
Expand Down

0 comments on commit 8a6803a

Please sign in to comment.