Skip to content

Commit

Permalink
Reverse of a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit-SE committed Mar 1, 2023
1 parent b6aae28 commit b7f48ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ReverseString.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
/* Reverse of a string
* Arijit = tijirA
*/
import java.util.*;
public class ReverseString {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();

/* One method
--------------------------------------
for (int i = s.length()-1; i>=0; i--) {
System.out.print(s.charAt(i)+"");
}
*/
// Another method
//-----------------------------------
String n = "";
for (int i = 0; i < s.length(); i++) {
n = s.charAt(i)+n;
}
System.out.println(n);
}
}

0 comments on commit b7f48ce

Please sign in to comment.