# artemkorsakov's solution

## to Reverse String in the Java Track

Published at Jan 29 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

Reverse a string

For example: input: "cool" output: "looc"

# Java Tips

For more help on how to solve this exercise, please refer to the tutorial provided as part of the hello world exercise: TUTORIAL.md

# Running the tests

You can run all the tests for an exercise by entering

``````\$ gradle test
``````

## Source

Introductory challenge to reverse an input string https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

### ReverseStringTest.java

``````import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ReverseStringTest {

@Test
public void testAnEmptyString() {
assertEquals("", new ReverseString().reverse(""));
}

@Ignore("Remove to run test")
@Test
public void testAWord() {
assertEquals("tobor", new ReverseString().reverse("robot"));
}

@Ignore("Remove to run test")
@Test
public void testACapitalizedWord() {
assertEquals("nemaR", new ReverseString().reverse("Ramen"));
}

@Ignore("Remove to run test")
@Test
public void testASentenceWithPunctuation() {
assertEquals("!yrgnuh m'I", new ReverseString().reverse("I'm hungry!"));
}

@Ignore("Remove to run test")
@Test
public void testAPalindrome() {
assertEquals("racecar", new ReverseString().reverse("racecar"));
}

}``````
``````class ReverseString {

String reverse(String inputString) {
StringBuilder sb = new StringBuilder();
for (int i = inputString.length() - 1; i >= 0; i--) {
sb.append(inputString.charAt(i));
}
return sb.toString();
}

}``````