|
| 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