forked from divScorp/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_Tokenizer_2
More file actions
42 lines (40 loc) · 992 Bytes
/
String_Tokenizer_2
File metadata and controls
42 lines (40 loc) · 992 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
//swap_first_and_last_letter_of_each_word
import java.util.*;
public class swap_first_and_last_letter_of_each_word
{
public static void main()
{
Scanner ob=new Scanner(System.in);
System.out.println("enter string");
String s=ob.nextLine();
StringTokenizer str=new StringTokenizer(s," ,.,?,!");
int n=str.countTokens();
String a[]=new String[n];
int i,b,k=0;String c[]=new String [n];String s1="";
for(i=0;i<n;i++)
{
a[i]=str.nextToken();
}
for(i=0;i<n;i++)
{
b=a[i].length();
char x=a[i].charAt(0);
if(b>1)
{
char y=a[i].charAt(b-1);
s1=y+a[i].substring(1,(b-1))+x;
}
else
{
s1=s1+x;
}
c[k]=s1;
k++;
s1="";
}
for(i=0;i<n;i++)
{
System.out.println(c[i]);
}
}
}