Write a method header on line two with the following specs:
Returns: a boolean
Name: bothEven
Parameters:
-
an integer called "num1"
-
an integer called "num2"
Then, starting on line 4, write code that will return true if both num1 and num2 are even. Return false otherwise.
Examples:
-
bothEven(4,6) ==> true
-
bothEven(3,4) ==> false
-
bothEven(-1,1) ==> false
1
2
3
4
5
6
7
8
9
10
11
12
13
|
class Main {
public static boolean bothEven(int num1, int num2)
{
return (num1%2==0 && num2%2==0)?true:false;
}
//test case below (dont change):
public static void main(String[] args){
System.out.println(bothEven(8,6)); //should be true
System.out.println(bothEven(5,6)); //should be false
}
}
|
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
043 - Method Header Practice 8 (0) | 2019.12.19 |
---|---|
042 - Method Header Practice 7 (0) | 2019.12.19 |
040 - Method Header Practice 5 (0) | 2019.12.19 |
039 - Method Header Practice 4 (0) | 2019.12.19 |
038 - Method Header Practice 3 (0) | 2019.12.10 |