Advertisement
Guest User

ElectronicMessage

a guest
Nov 5th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class ElectronicMessage {
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. String [] input = scan.nextLine().split(" ");
  10. int counter = 0;
  11. int tempCounter = 0;
  12. String allWords = "";
  13.  
  14. for (int i = 0; i < input.length; i++) {
  15. allWords = input[i];
  16.  
  17. String specialCharactersString = "!@#$%^&*()_+-=><?";
  18. for (int k = 0; k < allWords.length(); k++) {
  19. char ch = allWords.charAt(k);
  20. if (specialCharactersString.contains(Character.toString(ch))) {
  21. tempCounter++;
  22. }
  23. if ((Character.toString(ch)).matches(".*[a-zA-Z].*") ||
  24. (Character.toString(ch)).matches(".*[0-9].*")) {
  25. if (counter < tempCounter) {
  26. counter = tempCounter;
  27. }
  28. tempCounter = 0;
  29. }
  30. }
  31. if (counter < tempCounter) {
  32. counter = tempCounter;
  33. }
  34. tempCounter = 0;
  35. }
  36. System.out.println(counter);
  37.  
  38.  
  39.  
  40.  
  41. }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement