-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreverse_string&word.java
More file actions
42 lines (38 loc) · 1015 Bytes
/
reverse_string&word.java
File metadata and controls
42 lines (38 loc) · 1015 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
//Program to Reverse every Word along with the String.
import java.util.*;
public class reverse_word
{
public static String palat(String str)
{
char chr[]=str.toCharArray();
int l=0,r=0;
for(int i=0;i<chr.length;i++)
{
l=i;
r=i;
while(r<chr.length && chr[i]!=' ')
{
r++;
}
i=r;
r--;
int x=l,y=r;
while(l<r)
{
char temp=chr[l];
chr[l]=chr[r];
chr[r]=temp;
l++;
r--;
}
}
return new String(chr);
}
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String :");
String str=new String(sc.nextLine());
System.out.println("The reversed word string is :"+ palat(str));
}
}