Senior
//list of car license plates, the numbers are always of a standard type // need to output each number separately to the console // then create a map of number - its digits (example A123BC:123) where key is A123BC and value is 123 //var autoNumbers = List.of(List.of("A123BC", "B421FT"), List.of("0543EC","B421FT", "I2220A")); import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here } }
sobes.tech AI
Answer from AI
java import java.util.*;
class Codechef { public static void main(String[] args) { var autoNumbers = List.of( List.of("A123BC", "B421FT"), List.of("0543EC", "B421FT", "I2220A") );
// Print each number separately
for (List<String> sublist : autoNumbers) {
for (String number : sublist) {
System.out.println(number);
}
}
// Create a map from number to digits in the number
Map<String, String> numberToDigits = new HashMap<>();
for (List<String> sublist : autoNumbers) {
for (String number : sublist) {
// Extract digits from the number
String digits = number.replaceAll("\\D", "");
numberToDigits.put(number, digits);
}
}
// Print the map
System.out.println("Map number -> digits:");
numberToDigits.forEach((key, value) -> System.out.println(key + ":" + value));
}
}