Advertisement
LoraOrliGeo

P1-FinalExam-Group1

Apr 14th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package a4_FINAL_EXAM_14March2019;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class P1 {
  8.     public static void main(String[] args) {
  9.         @SuppressWarnings("resource")
  10.  
  11.         Scanner sc = new Scanner(System.in);
  12.        
  13.         String line = "";
  14.        
  15.         String regex = "^(?<name>[A-Za-z\\d!@#$?]+)=(?<length>[\\d]+)<<(?<geohash>.+)$";
  16.         Pattern pattern = Pattern.compile(regex);
  17.        
  18.         while (!"Last note".equals(line = sc.nextLine())) {
  19.             Matcher matcher = pattern.matcher(line);
  20.            
  21.             if (matcher.find()) {
  22.                 String name = matcher.group("name").replaceAll("[!@#$?]", "");
  23.                 int lenghtOfGeohash = Integer.parseInt(matcher.group("length"));
  24.                 String geohashCode = matcher.group("geohash");
  25.                
  26.                 if (geohashCode.length() == lenghtOfGeohash) {
  27.                     System.out.println(String.format("Coordinates found! %s -> %s", name, geohashCode));
  28.                 } else {
  29.                     System.out.println("Nothing found!");
  30.                 }
  31.             } else {
  32.                 System.out.println("Nothing found!");
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement