Advertisement
brandblox

Untitled

Jan 9th, 2022
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. /*Name: Arijit Deb
  2. * Roll: 17 UID: 7074522
  3. * Class: 12Sc.A
  4. */
  5. import java.util.*;
  6. class CLass_Test_2020{
  7. public static void main(){//opens main
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("Enter:");
  10. String s = sc.nextLine();
  11. s=s.toUpperCase();
  12. int n=s.length(), c=0;
  13. for(int i=0; i<n; i++)
  14. { char k=s.charAt(i);
  15. if(k=='.'||k==','||k==';'||k==':' || k==' ')
  16. c++;
  17. }
  18. String word[] = new String[c];
  19. c=0;
  20. String w="", cons="";
  21. for(int i=0; i<n; i++)
  22. { char k=s.charAt(i);
  23. if(k=='.'||k==','||k==';'||k==':' || k==' '){
  24. if(c>0)
  25. { if(word[c-1].charAt(word[c-1].length()-1) == w.charAt(w.length()-1))
  26. cons = cons+word[c-1]+" "+w+",";
  27. }
  28. word[c++]=w;
  29. w = "";
  30. }
  31. else
  32. {if(k=='\'')
  33. k='\0';
  34. w=w+k;
  35. }
  36. }
  37. int ct=0, spc=0;
  38. while(true)
  39. { for(int j=0; j<c; j++)
  40. { if(ct<word[j].length())
  41. System.out.print(word[j].charAt(ct)+" ");
  42. else{
  43. System.out.print(" ");
  44. spc++;
  45. }
  46. }
  47. System.out.println();
  48. ct++;
  49. if(spc==c)
  50. break;
  51. spc=0;
  52. }
  53. String y="";
  54. System.out.println("Consecutive words ending with same character: ");
  55. int counter1= 0;
  56. if(cons!="")
  57. for(int i=0; i<cons.length(); i++)
  58. { if(cons.charAt(i)==','){
  59. System.out.println(y);
  60. y="";
  61. counter1++;
  62. }
  63. else
  64. y=y+cons.charAt(i);
  65. }
  66.  
  67. else
  68. System.out.println("None");
  69. System.out.println("No. of consecutive words: "+(counter1+1));
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement