-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversing.java
More file actions
43 lines (43 loc) · 802 Bytes
/
Reversing.java
File metadata and controls
43 lines (43 loc) · 802 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
42
43
import java.util.*;
public class Reversing
{
String st[];
int top;
int max;
Reversing(int m)
{
max=m;
top=-1;
st=new String[max];
}
void push(String s)
{
if(top==max-1){
System.out.println("Stack full");
return;
}
else{
top=top+1;
st[top]=s;
}
}
void display()
{
for(int i=top;i>=0;i--)
System.out.print(st[i]);
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
String s=in.nextLine();
if(s.length()<1 || s.length()>100000)
return;
Reversing obj=new Reversing(s.length());
String stack[]=s.split("");
for(String i:stack)
{
obj.push(i);
}
obj.display();
}
}