Hey everyone, so i am trying to write a program that takes the first letter of a string, concats it to the end of the string and can spell the original string backwards.
For example,
I have a string called
"grammar"
take the first letter "g" and add it to the end
"grammar"
g ----->
This equals "rammarg" which is "grammar" spelled backwards. Other examples are "revive, potato, uneven"
The end result is i have to compare the string backwards with the one that is concatenated
The issue that i am running in to is i can concat the first letter of the string to the end just fine, but when i use a loop to spell the word backwards i have no way of using that loop and applying it to a variable so i can compare the two strings.
I CAN'T use the "StringBuffer.reverse" method and have to use a loop to compare them
public static void main(String[]args) { //creates string called word String word; Scanner keyboard = new Scanner(System.in); // initalizes scanner System.out.println("Enter a word (type exit to end the program) :"); //prompts the user to enter in the word word = keyboard.next(); //allows the word to be taken in //Initialize first character of the string word char wordfc = word.charAt(0); //convert from character to string String firstchar = Character.toString(wordfc); //word with first char gone String last = word.substring(1); //letter at end // adds the first character of wordfc to the end of the substring last String lae = last.concat(firstchar); //System.out.println(lae); // This is the loop(below) that prints the word backwards, //how would i assign this to a variable to compare to "lae" which is the "word" concatenated. int i = word.length()-1; for( ; i>=0; ) { System.out.print( word.charAt(i--)); } /*I am basically wanting this loop above to compare to lae as in if(lae.equals(stringbw)) { Syso("yes') } else Syso("no") */
Thank you all in advanced for your help!