One of my AP projects includes separating each word from a string, I have tried accomplishing numerous times yet with no success! My class has not yet learned about arrays, regex, or split yet so if you could help please avoid any of those. However we did learn substring, charAt, indexOf, length, trim ...
This is one of my attempts:
(notice that in order for me to actually notice I've split them I try adding N
to the string I am re-creating, which is newWord)
public class Functions {
public static String stringReversal(String word){
if (word.length() <= 1){
return word;
}else{
char c = word.charAt(0);
return stringReversal(word.substring(1)) + c;
}
}
public static Boolean palindrome(String word){
Boolean palindrome;
if (word.equalsIgnoreCase(stringReversal(word))){
return palindrome = true;
} else{
return palindrome = false;
}
}
public static String pigLatin(String sentence){
if(sentence.length() <= 1){
return sentence;
} else {
String newWord = "";
return newWord += pigLatin(sentence.substring(0, sentence.indexOf(" "))) + " N ";
}
}
}
Main:
public class Main {
public static void main (String [] args){
Scanner in = new Scanner(System.in);
String word = in.nextLine();
System.out.println(Functions.test(word));
}
}
However the output only print N
! Can anyone please help and show a way that I can accomplish this, I've tried many ideas yet none worked.