Reverse a String in Java | Data Structure and algorithm

 


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







Post a Comment

0 Comments