Advertisement
Guest User

Untitled

a guest
Feb 6th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class Game_1 {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. //Getting the phrase inside an array
  9. String a = scanner.nextLine();
  10. a = a.replace(" ", "");
  11. a = a.replace(".", "a");
  12. a = a.toLowerCase();
  13. String[] phrase = a.split("");
  14.  
  15. //Getting the asci codes
  16. int[] asciArray = new int[phrase.length];
  17.  
  18. for (int i = 0; i < asciArray.length; i++) {
  19. asciArray[i] = (int) a.charAt(i);
  20. }
  21.  
  22.  
  23. //Counting the longest sequence
  24. int max = 0;
  25. int sequence = 0;
  26.  
  27.  
  28. for (int i = 0; i < asciArray.length; i++) {
  29. boolean lampa = true;
  30.  
  31. if ((asciArray[i] >= 48 && asciArray[i] <= 57)) {
  32. lampa = false;
  33. } else if ((asciArray[i] >= 97 && asciArray[i] <= 122)) {
  34. lampa = false;
  35. }
  36.  
  37. if (lampa) {
  38. sequence++;
  39. } else {
  40. if (sequence > max) {
  41. max = sequence;
  42. }
  43. sequence = 0;
  44. }
  45.  
  46.  
  47.  
  48. }
  49.  
  50. if(sequence>max){
  51. max = sequence;
  52. }
  53.  
  54. System.out.println(max);
  55.  
  56.  
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement