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

Write a method that takes a String as input and returns the reverse of that Stri

ID: 3529776 • Letter: W

Question

  1. Write a method that takes a String as input and returns the reverse of that String. Then write a second method that uses the first method to test whether or not an input String is apalindrome. Your method should return true if the String is a palindrome, and false otherwise.Palindromes were discussed in Exercise 2 of Closed Lab 06, and you should use the same definition here. In addition, write a main method that tests your method with a variety of Strings that should returntrueandfalsevalues.
  2. Using the methods you wrote for the above question, write a method that takes a Scanner as an input parameter and returns a String as a result. The method should print a prompt to the screen asking the user to enter a palindrome. It should then test the input. If it is not a palindrome, it should print an error message and continue asking for a palindrome until the user provides one. Once a palindrome has been input, the method should return it. In addition, write a main method that uses this method and displays the final palindrome to the screen.
  3. Write a method named rowOfStars that takes a single integer parameternand returns a String with that many stars in it. For example, calling the method with a value of 3 would cause the String "***" to be returned.
  4. Using the method you wrote for the previous question, write a method that takes a single integer parameternand prints a triangle of stars to the screen that has a height and base size equal ton. For example, calling the method with a value of 4 will produce the triangle:
     *
    **
    ***
    ****

Explanation / Answer

public class StringReverseWarray {
public static void main( String [] args ) {
String a = "abcdef";
String b = reverse( a );
System.out.println( b );
}

private static String reverse( String a ) {
String result = "";
for (int i = a.length() - 1; i >=0; i--) {
result += a.charAt(i);

}
return result;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote