File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ /* Alternative way to do the reversal program.
2+ @Author: Rasmus Knoth Nielsen
3+ */
4+
5+ public class SimpleReversal
6+ {
7+ public String reverse (String input )
8+ {
9+ // Create a StringBuilder to be able to use reverse() method
10+ StringBuilder output = new StringBuilder ();
11+ // Add the input to our output
12+ output .append (input );
13+ // Reverse the string
14+ output .reverse ();
15+ // Return the StringBuilder, as a string
16+ return "" + output ;
17+ }
18+
19+ // Main method to test if the reverse is successful
20+ public static void main (String [] args ) {
21+
22+ SimpleReversal simpleReversal = new SimpleReversal ();
23+ String string = "Testing string" ;
24+ System .out .println ("String before reversing: " + string );
25+ System .out .println ("String after reversing: " + simpleReversal .reverse (string ));
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments