Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import com.sun.security.jgss.GSSUtil;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Retake2 {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         String input = scanner.nextLine();
  12.         Pattern pattern1 = Pattern.compile("@+[A-z]{3,}@@[A-z]+@+|#+[A-z]{3,}##[A-z]+#+");
  13.         int count = 0;
  14.  
  15.         Matcher matcher = pattern1.matcher(input);
  16.  
  17.  
  18.         while (matcher.find()) {
  19.  
  20.  
  21.             count++;
  22.  
  23.         }
  24.         System.out.printf("%d word pairs found!", count);
  25.         System.out.println("The mirror words are:");
  26.         System.out.println();
  27.     }
  28.  
  29.     static boolean isPalindrome(String str) {
  30.  
  31.         // Pointers pointing to the beginning
  32.         // and the end of the string
  33.         int i = 0, j = str.length() - 1;
  34.  
  35.         // While there are characters toc compare
  36.         while (i < j) {
  37.  
  38.             // If there is a mismatch
  39.             if (str.charAt(i) != str.charAt(j))
  40.                 return false;
  41.  
  42.             // Increment first pointer and
  43.             // decrement the other
  44.             i++;
  45.             j--;
  46.         }
  47.  
  48.         // Given string is a palindrome
  49.         return true;
  50.     }
  51. }
  52.     // Driver code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement