返回列表 發帖

TQC 203 判斷奇偶數

使用者自行輸入一個數值
並使用方法來判斷是否為奇偶數
  1. import java.util.*;
  2. public class JPD02 {
  3.     static Scanner input = new Scanner(System.in);
  4.     public static void main(String[] args) {
  5.             int num = input.nextInt();
  6.             test(num);
  7.             num = input.nextInt();
  8.         test(num);
  9.     }
  10.    
  11.     static void test(int num) {

  12.             if(num%2==0)
  13.             {
  14.                     System.out.println("the number is even.");
  15.             }else{
  16.                     System.out.println("the number is odd.");

  17.             }
  18.            
  19.     }
  20. }
複製代碼

返回列表