Question: How can i write this code with java? Write a method that takes any String as input and returns a new String that is the

How can i write this code with java?

Write a method that takes any String as input and returns a new String that is the reverse of the oringal string.

Do this by creating an initially empty string, and then looping through the input string in reverse order, getting each character with charAt(), and adding each character onto the end of the new String. (We want you to do it this way.)

If we have

String str1 = "Java is fun.";

String str2 = reverseString(str1);

System.out.println(str2);

The output will be: .nuf is avaJ

The method would be defined as:

public static String reverseString(String s){

String newString = ""; // make an empty String

// You fill this in.

return newString;

}

Write a main() method that tests the reversing method with at least the above string and one other string of your choosing. Print both the original and the reversed string.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!