205 倍數判斷

import java.util.*;
public class JPA205 {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    static void test() {
        System.out.println("Enter an integer:");
        int x=input.nextInt();
        if(x%6==0){
        System.out.println(x+"是2、3、6的倍數");
        }
        else if(x%2==0){
        System.out.println(x+"是2的倍數");
        }
        else if(x%3==0){
        System.out.println(x+"是3的倍數");
        }
        else{
        System.out.println(x+"不是2、3、6的倍數");
        }
    }
}

沒有留言:

張貼留言