-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverse_String.java
More file actions
35 lines (35 loc) · 923 Bytes
/
Copy pathReverse_String.java
File metadata and controls
35 lines (35 loc) · 923 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
import java.util.Scanner;
class Reverse_String
{
public static void main(String args[])
{
String str,r="",s="",st="";
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string: ");
str=sc.nextLine();
str=str+' ';
int l=str.length();
if(str.charAt(l-2)=='.')
{
for(int i=0;i<l-2;i++)
{
st=st+str.charAt(i) ;
}
st=st+' ';
for(int j=0;j<st.length();j++)
{
if(st.charAt(j)!=' ')
r=r+st.charAt(j);
else
{
s=r+' '+s;
r="";
}
}
System.out.println("The original String "+str);
System.out.println("The reversed String "+s+".");
}
else
System.out.println("Invalid string");
}
}