使用者自行輸入一個數值
並使用方法來判斷是否為奇偶數- import java.util.*;
- public class JPD02 {
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args) {
- int num = input.nextInt();
- test(num);
- num = input.nextInt();
- test(num);
- }
-
- static void test(int num) {
- if(num%2==0)
- {
- System.out.println("the number is even.");
- }else{
- System.out.println("the number is odd.");
- }
-
- }
- }
複製代碼 |