-
-
Save vaughan0/5078026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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