始める無料で始める

新しい価格

政府が新しい税を導入しました。すべての在庫価格を一度に更新し、各価格にその値の半分を上乗せしたいとします。

この演習はコースの一部です

中級 Java

コースを見る

演習の手順

  • 関数に正しいを指定してください。
  • 引数の 1.5 倍を返してください。
  • 適切な種類の for ループを使ってください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

class PriceCalculator {
  // Give the correct type to your function
  static ____ oneAndAHalf(double a) {
    // Use the proper operations to get the result
    return ____;
  }

  public static void main(String[] args) {
    double[] numbers = {76, 38.3, 10, 42, 98.5, 84, 50, 72.2, 98, 96};

    // Use the congruous type of for loop
    for (____) {
      numbers[i] = oneAndAHalf(numbers[i]);
      System.out.println(numbers[i]);
    }
  }
}
コードを編集して実行