Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I am having trouble reversing a string within the palindrome program that I a

ID: 3656923 • Letter: H

Question

Hi I am having trouble reversing a string within the palindrome program that I am writing. The programs that I am writing is supposed to generate a palindrome word (the word doesn't have to make sense). What I am doing to generate the palindrome is randomly generating numbers that correlated to letters in a string and then printing the random letters out. What I am getting stuck on is taking the string I generated and reversing it then adding the reversed string back to generated word thus creating a palindrome. so lets say the generated string is "sdgf" when the string is reversed it will look like "fgds" then I'll add the generated string to the reversed string to make a palindrome. "sdgffgds" Can someone please show me how to reverse the string and add it? Detailed explanation and example please!! import java.util.Random; public class IterativePalindromGenerator { public static void main(String[] args) { Random random = new Random(); int floorValue = 1; int cielingValue = 20; int randomNumber = random.nextInt(cielingValue - floorValue) + floorValue; String alphabetLetters = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < randomNumber; i++) { char generatedLetters = alphabetLetters.charAt(random.nextInt(alphabetLetters.length())); String generatedLetterSTRINGType = Character.toString(generatedLetters);// converts char to string System.out.print(generatedLetterSTRINGType); } } }

Explanation / Answer

import java.util.Random; public class IterativePalindromGenerator { public static void main(String[] args) { Random random = new Random(); int floorValue = 1; int cielingValue = 20; int randomNumber = random.nextInt(cielingValue - floorValue) + floorValue; String alphabetLetters = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i = 0; --i) { sb.append(s.charAt(i)); } return sb.toString(); } }