Increment Array Elements


Submit solution

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

Authors:
Problem type

題目說明

請撰寫一個名為 incrementArray 的函式,接收一個整數陣列與一個浮點數作為參數,回傳一個新的浮點數陣列,其內容為原始陣列每個元素加上該浮點數後的結果。

請完成註解TODO部分,使程式符合題目要求。

⚠️ 請依照程式模板進行撰寫,若人工檢查時發現結構變更將無法得分。

import java.util.Scanner;

public class MyProgram {
    public static void main(String[] args) {
        /*
        *TODO: 請完成此部分缺失程式碼
        */

        double[] newArray = incrementArray(array, value);

        for (int i = 0; i < newArray.length; i++) {
            System.out.print(newArray[i] + " ");
        }

        scanner.close();
    }

    // TODO: 請實作 incrementArray 函式

}

輸入

輸入一個整數 N,表示陣列長度

接著輸入 N 個整數,作為原始陣列內容

再輸入一個浮點數,作為每個元素的加值

輸出

輸出加值後的浮點數陣列,每個元素之間以一個空格分隔(同一行輸出)

範例輸入 #1

5
1 2 3 4 5
0.5

範例輸出 #1

1.5 2.5 3.5 4.5 5.5

範例輸入 #2

3
10 20 30
1.0

範例輸出 #2

11.0 21.0 31.0

Comments

There are no comments at the moment.