Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Name: Arijit Deb
- * Roll: 17 UID: 7074522
- * Class: 12Sc.A
- */
- import java.util.*;
- class CLass_Test_2020{
- public static void main(){//opens main
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter:");
- String s = sc.nextLine();
- s=s.toUpperCase();
- int n=s.length(), c=0;
- for(int i=0; i<n; i++)
- { char k=s.charAt(i);
- if(k=='.'||k==','||k==';'||k==':' || k==' ')
- c++;
- }
- String word[] = new String[c];
- c=0;
- String w="", cons="";
- for(int i=0; i<n; i++)
- { char k=s.charAt(i);
- if(k=='.'||k==','||k==';'||k==':' || k==' '){
- if(c>0)
- { if(word[c-1].charAt(word[c-1].length()-1) == w.charAt(w.length()-1))
- cons = cons+word[c-1]+" "+w+",";
- }
- word[c++]=w;
- w = "";
- }
- else
- {if(k=='\'')
- k='\0';
- w=w+k;
- }
- }
- int ct=0, spc=0;
- while(true)
- { for(int j=0; j<c; j++)
- { if(ct<word[j].length())
- System.out.print(word[j].charAt(ct)+" ");
- else{
- System.out.print(" ");
- spc++;
- }
- }
- System.out.println();
- ct++;
- if(spc==c)
- break;
- spc=0;
- }
- String y="";
- System.out.println("Consecutive words ending with same character: ");
- int counter1= 0;
- if(cons!="")
- for(int i=0; i<cons.length(); i++)
- { if(cons.charAt(i)==','){
- System.out.println(y);
- y="";
- counter1++;
- }
- else
- y=y+cons.charAt(i);
- }
- else
- System.out.println("None");
- System.out.println("No. of consecutive words: "+(counter1+1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement