BaşlayınÜcretsiz Başlayın

Pattern finding

You need to group sales by platform generation for a trend analysis. By extracting version numbers from platform names, you can categorize sales across different console generations. You've extracted some platform names from the video game dataset.

The necessary packages such as CharMatcher, and Pattern have been imported for you.

Bu egzersiz

Cleaning Data in Java

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Check if the matcher finds any version number.
  • Report the version number that the matcher finds.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

public class PatternValidation {
    public static void main(String[] args) {
        List platforms = Arrays.asList("PlayStation 5", "PlayStation 4", "Xbox One", "Switch");
        Pattern versionPattern = Pattern.compile("\\d");  // Match single digit versions

        for (String platform : platforms) {
            Matcher matcher = versionPattern.matcher(platform);
            // Check if the matcher finds any version number
            if (____.____()) {
                // Report the version number that the matcher finds
                System.out.println(platform + ": version " + ____.____());
            } else {
                System.out.println(platform + ": no version number");
            }
        }
    }
}
Kodu Düzenle ve Çalıştır