-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReverseString.java
More file actions
42 lines (40 loc) · 896 Bytes
/
ReverseString.java
File metadata and controls
42 lines (40 loc) · 896 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
*/
import java.util.*;
/**
* @author M.NAVEEN
* RANDOM CODER'S
* Tech/Project Lead Android Club
*/
public class ReverseString
{ private String str,output;
static Scanner nav=new Scanner(System.in);
public ReverseString(String str)
{
this.str=str;
output="";
}
public String reverse(String str)
{
String s[]=str.split("");
System.out.println("Initial String :"+Arrays.toString(s));
for(int i=s.length -1;i>=0;i--)
{
output=output+s[i];
}
//System.out.println(output);
output=output+" ";
return output;
}
public static void main(String ...strings)
{
System.out.println("Enter the String to find reverse");
String a=nav.nextLine();
ReverseString rs=new ReverseString(a);
String temp[]=a.split(" ");
for(int i=temp.length-1;i>=0;i--)
rs.reverse(temp[i]);
System.out.println("Reverse String :"+rs.output);
}
}