Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a4_FINAL_EXAM_14March2019;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class P1 {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- String line = "";
- String regex = "^(?<name>[A-Za-z\\d!@#$?]+)=(?<length>[\\d]+)<<(?<geohash>.+)$";
- Pattern pattern = Pattern.compile(regex);
- while (!"Last note".equals(line = sc.nextLine())) {
- Matcher matcher = pattern.matcher(line);
- if (matcher.find()) {
- String name = matcher.group("name").replaceAll("[!@#$?]", "");
- int lenghtOfGeohash = Integer.parseInt(matcher.group("length"));
- String geohashCode = matcher.group("geohash");
- if (geohashCode.length() == lenghtOfGeohash) {
- System.out.println(String.format("Coordinates found! %s -> %s", name, geohashCode));
- } else {
- System.out.println("Nothing found!");
- }
- } else {
- System.out.println("Nothing found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement