changefunc


Submit solution

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

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

請參考底下程式碼,並請寫一個計算式為(x - y) * (x + y / 2)的函式

public class MyProgram {
    public static void main(String[] args) {
        // call a function to increment 0.5
        int value = 5;
        System.out.println(value);
        double newValue = increment(value, 0.3);
        System.out.println(newValue);
    }

    // function to increment a value
    public static double increment(int x, double y) {
        double result = x + y;
        return result;
    }
}

輸入限制 整數

輸入

x y

輸出

算出的結果

測試資料1 輸入

1 2

測試資料1 輸出

-2

Comments


  • -1
    scu09156238  commented on April 12, 2024, 3:32 p.m.

    題解

    import java.util.Scanner;
    
    public class t04111 {
    
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int x = in.nextInt();
            int y = in.nextInt();
            in.close();
            int newValue = increment(x, y);
            System.out.println(newValue);
        }
    
        // function to increment a value
        public static int increment(int x, int y) {
            int result = (x - y) * (x + y / 2);
            return result;
        }
    }