開始使用免費開始

尋找樣式

你需要依「平台世代」彙總銷售額,才能做趨勢分析。透過從平台名稱中擷取版本號,你可以把不同主機世代的銷售額分類。你已經從電玩遊戲資料集中擷取了一些平台名稱。

必要的套件(例如 CharMatcherPattern)都已為你匯入。

本練習屬於課程

使用 Java 進行資料清理

檢視課程

練習說明

  • 檢查 matcher 是否能找到任何版本號。
  • 回報 matcher 找到的版本號。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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");
            }
        }
    }
}
編輯並執行程式碼