接受两个整数值作为输入参数和 returns 布尔值的方法

A method which accepts two integer values as input parameters and returns the boolean

这是测试的练习题之一:

Write a method which accepts two integer values as input parameters and returns the boolean result true if the sum of the inputs is greater than or equal to 10 (and falseotherwise)

我的回答如下,但我认为它看起来不正确。谁能指点一下?

public class Bruh{
    public static void main (String [] arg){
        int a;
        int b;
        boolean sum = true;
        if ( a+b > 10)
          System.out.println ("yo");
        else{ 
            sum = false;
        }
    }
}

您只在 main 方法中编写了一些代码,但没有创建。

为了做到这一点,您需要在 Bruh class 中实际创建一个方法,例如:

public static boolean isSumGreaterThan9(int a, int b){
    return (a + b) > 9;
}

比从 main 方法调用它:

public static void main (String [] arg){
    int a = 4; // or whatever
    int b = 7; // or whatever
    System.out.println(isSumGreaterThan9(a, b));
}

您需要将您的逻辑放入一个方法中,并根据要求将您的比较更改为 >=

public static boolean isSumGreaterThanOrEqualToTen(int a, int b) {
    return (a + b) >= 10;    
}