- 윷놀이 만들기(Yut Play)
public class YutPlay {
public static void main(String[] args) {
for (int i = 0 ; i < 20 ; i++) {
int play = (int)(Math.random() * 16 + 1);
switch (play) {
case 1:
System.out.println("\'빽도\'입니다.");
break;
case 2: case 3: case 4:
System.out.println("\'도\'입니다.");
break;
case 5: case 6: case 7: case 8: case 9: case 10:
System.out.println("\'개\'입니다.");
break;
case 11: case 12: case 13 : case 14:
System.out.println("\'걸\'입니다.");
break;
case 15:
System.out.println("\'윷\'입니다.");
break;
case 16:
System.out.println("\'모\'입니다.");
break;
default:
break;
}
}
}
}
public class YutPlay2 {
public static void main(String[] args) {
int r1 =(int)(Math.random() * 2); // 0, 1
int r2 =(int)(Math.random() * 2) * 3; // 0, 3
int r3 =(int)(Math.random() * 2) * 5; // 0, 5
int r4 =(int)(Math.random() * 2) * 7; // 0, 7
// 0 1 2 3 4
switch (r1 + r2 + r3 + r4) {
case 0:
System.out.println("모");
break;
case 1:
System.out.println("도");
break;
case 2:
System.out.println("개");
break;
case 3:
System.out.println("걸");
break;
case 4:
System.out.println("윷");
break;
default:
break;
}
}
}