Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ac50c56

Browse files
Create String_Tokenizer_2
1 parent f202f38 commit ac50c56

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎String/String_Tokenizer_2‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//swap_first_and_last_letter_of_each_word
2+
3+
import java.util.*;
4+
public class swap_first_and_last_letter_of_each_word
5+
{
6+
public static void main()
7+
{
8+
Scanner ob=new Scanner(System.in);
9+
System.out.println("enter string");
10+
String s=ob.nextLine();
11+
StringTokenizer str=new StringTokenizer(s," ,.,?,!");
12+
int n=str.countTokens();
13+
String a[]=new String[n];
14+
int i,b,k=0;String c[]=new String [n];String s1="";
15+
for(i=0;i<n;i++)
16+
{
17+
a[i]=str.nextToken();
18+
}
19+
for(i=0;i<n;i++)
20+
{
21+
b=a[i].length();
22+
char x=a[i].charAt(0);
23+
if(b>1)
24+
{
25+
char y=a[i].charAt(b-1);
26+
27+
s1=y+a[i].substring(1,(b-1))+x;
28+
}
29+
else
30+
{
31+
s1=s1+x;
32+
}
33+
c[k]=s1;
34+
k++;
35+
s1="";
36+
}
37+
for(i=0;i<n;i++)
38+
{
39+
System.out.println(c[i]);
40+
}
41+
}
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /