File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #https://www.facebook.com/profile.php?id=100013277143928&__tn__=%2CdC-R-R&eid=ARBKbLxMZblgtFE4DpGns8ObnqM8AwcGnliVKTU_RNGlr2ePyy5v4Pn3iYvCKxZa0XLaGMlr3qDi5TlC&hc_ref=ARQ24E17s7oDHvteqiO7eOM3KzHs079jvEC9GCUvn4TCq5SdVIPDZK9jkcBpFkwXxfY&fref=nf
2+
3+ import java.util.Scanner;
4+ class MainStr12
5+ {
6+ public static void main(String[] args)
7+ {
8+ Scanner sc= new Scanner(System.in);
9+ System.out.println("Enter the Sentence.. ");
10+ String st=sc.nextLine();
11+ char ch[]=st.toCharArray();// string charcter array
12+ int f=0;
13+ int l=0;
14+ for(int i=0;i<ch.length;i++)
15+ {
16+
17+ if(i==0&&ch[i]!=' '||ch[i]!=' '&&ch[i-1]==' ')
18+ {
19+ f=i;
20+ }
21+
22+ if(i==ch.length-1&&ch[i]!=' '||ch[i]!=' '&&ch[i+1]==' ')
23+ {
24+ l=i;
25+
26+ char temp=ch[f];
27+ ch[f]=ch[l];
28+ ch[l]=temp;
29+ }
30+ }
31+
32+ st=new String(ch);//charcter array to String
33+ System.out.println(st);
34+
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments