java
1public class Main {
2 private final static String[] MESSAGES = {
3 "2の倍数でも3の倍数でもありません",
4 "2の倍数か3の倍数です",
5 "2と3の公倍数です"
6 };
7
8 private static String check_num(int num) {
9 int flag_2 = (num % 2 == 0) ? 1 : 0;
10 int flag_3 = (num % 3 == 0) ? 1 : 0;
11 return "" + num + " は" + MESSAGES[flag_2 + flag_3];
12 }
13
14 public static void main(String[] args) {
15 for (int i = 1; i < 16; i++) {
16 System.out.println(check_num(i));
17 }
18
19 int i = 1;
20 while (i < 16) {
21 System.out.println(check_num(i));
22 i += 1;
23 }
24 }
25}