Skip to content

Instantly share code, notes, and snippets.

@vaughan0
Forked from anonymous/gist:5077996
Last active December 14, 2015 11:18
Show Gist options
  • Save vaughan0/5078026 to your computer and use it in GitHub Desktop.
Save vaughan0/5078026 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class FirstFour {
public static void main(String [] args)
{
String word;
System.out.println("Enter a word here");
Scanner in = new Scanner(System.in);
word = in.nextLine();
reverse(word);
}
public static void reverse(String word)
{
char[] wordArray = word.toCharArray();
int i = 0;
int j = wordArray.length-1;
while (i < j)
{
char b = wordArray[i];
wordArray[i] = wordArray[j];
wordArray[j] = b;
i++; j--;
}
System.out.println("The reverse is:" + new String(wordArray));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment