Life Path Number


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem types
Allowed languages
Java 19, Java 8

題目說明

計算生命靈數

出生西元年、月、日的每個數相加
若得出雙位數則繼續相加,直到最終得出個位數
舉例:20240322 -> 2+0+2+4+0+3+2+2=15、1+5=6 -> 生命靈數:6

vvv請使用以下程式碼作答vvv

import java.util.Scanner;

public class LifePathNumber {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        String dateLine = input.next();
        input.close();

        int add = Integer.parseInt(dateLine);
        if (!isDateCorrect(dateLine)) {
            System.out.print(dateLine + " is wrong date.");
        } else {
            do {
                add = addAllNums(add + "");
            } while (add > 9);
            System.out.print(dateLine + " -> " + add);
        }
    }

    public static boolean isDateCorrect(String dateLine) {
        // 套用第1題做修改
        // ...
        // 記得寫return!!
    }

    public static int addAllNums(String stringNum) {
        // 套用第2題做修改
        // ...
        // 記得寫return!!
    }

}

輸入限制

長度為8的數字,首位不為0

輸入

西元年月日(長度為8的數字,不含空格)

輸出

先判斷輸入的日期是否正確(使用 第一題 程式碼)
若有誤,輸出(input_date) is wrong date.
若無誤則計算生命靈數(使用 第二題 程式碼),輸出(input_date) -> (life_path_num)

測試資料0 輸入

20240203

測試資料0 輸出

20240203 -> 4

測試資料1 輸入

19880740

測試資料1 輸出

19880740 is wrong date.

測試資料2 輸入

20010229

測試資料2 輸出

20010229 is wrong date.

Comments

There are no comments at the moment.