Advertisement
TUNVAN

Untitled

Nov 6th, 2022
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exercise2 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.         int counterMaxSequence = 0;
  8.         int counter = 0;
  9.         boolean isSpecialSymbol;
  10.  
  11.         for (int i = 0; i < input.length(); i++) {
  12.             char symbol = input.charAt(i);
  13.  
  14.             isSpecialSymbol = (int) symbol >= 33 && (int) symbol <= 45 || (int) symbol >= 58 && (int) symbol <= 64 || (int) symbol >= 91 && (int) symbol <= 96;
  15.  
  16.             if (isSpecialSymbol) {
  17.                 counter++;
  18.             } else {
  19.                 if (counter > 0) {
  20.                     if (counterMaxSequence < counter) {
  21.                         counterMaxSequence = counter;
  22.  
  23.                     }
  24.                     counter = 0;
  25.                 }
  26.             }
  27.         }
  28.         System.out.println(counterMaxSequence);
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement