Skip to content

Instantly share code, notes, and snippets.

@Neptune998
Created December 12, 2021 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neptune998/eaa7e58d12de954810af59f1b8fdc7ce to your computer and use it in GitHub Desktop.
Save Neptune998/eaa7e58d12de954810af59f1b8fdc7ce to your computer and use it in GitHub Desktop.
String Reversal Using CharAt Method in Java.
import java.io.*;
import java.util.Scanner;
//java program to reverse a word
class ReverseString {
public static void main(String[] args) {
String oriString = "NeptuneWorld";
String revString = "";
char ch;
System.out.println("String: " + oriString);
for (int i = 0; i < oriString.length(); i++) {
ch = oriString.charAt(i); // extracts character at ith location
revString = ch + revString; // add extract character at the given location
}
System.out.println("Reversed String : " + revString);
}
}
//Output:
//String: NeptuneWorld
//Reversed String : dlroWenutpeN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment