In this blog, we will learn how to reverse a string in Java
package learning;
import java.util.Scanner;
public class queueP {
public static void reverse(String a) {
if(a.length()==0) {
return;
}
char[] c = a.toCharArray();
int length = c.length-1;
for(int i =length ;i>=0;i--) {
System.out.print(c[i]);
}
}
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
String input = s.nextLine();
reverse(input);
}
}
Input : amit
Output : tima
To understand how this code work watch the vide
Other Blog you might be interested
0 Comments
if you are not getting it then ask i am glad to help