-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
26 lines (26 loc) · 609 Bytes
/
ReverseString.java
File metadata and controls
26 lines (26 loc) · 609 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.Scanner;
public class ReverseString
{
public static void main(String[] args)
{
String s;
System.out.println("Enter The string: ");
Scanner scanner = new Scanner(System.in);
s = scanner.nextLine();
Rev_str obj=new Rev_str();
obj.reverse(s);
}
}
class Rev_str
{
void reverse(String str)
{
if ((str==null)||(str.length() <= 1))
System.out.println(str);
else
{
System.out.print(str.charAt(str.length()-1));
reverse(str.substring(0,str.length()-1));
}
}
}