Reverse String Code in Java

Reverse String Code in Java


 here i define a valriable a String name = "AsgarAnsari";

then i add a loop which is starting from length of name and then decereasing length in side of For Loop

charAt(): it is a method return the character specific index in a string.

code Here

Class revString {
public static void main (string[] args){
String name = "AsgarAnsari";
String revName = "";
for(int i = name.length();i>=0;i--){
revName= revName+name.charAt(i);
}
System.out.println(i);
}
}


Output: irasnAragsA

No comments: