본문 바로가기

JABA

8.주사위 문제

주사위 문제

public class DiceTwo {

    public  static void main(String[] args) {
        final int MAX = 6; //주사위 최고 숫자
        final int MIN = 1; //주사위 최소 숫자

        final int RandomDice1 = (int)(Math.random() * 6) + 1; //주사의1 값은 랜덤 1~6
        final int RandomDice2 = (int)(Math.random() * 6) + 1; //주사위2 값은 랜덤 1~6

        System.out.println("주사위1의 값은 " + RandomDice1 + "입니다.");
        System.out.println("주사위2의 값은 " + RandomDice2 + "입니다.");

        int DiceSum = RandomDice1 + RandomDice2; //두 주사위의 합
        int number1 = DiceSum % 4; //4로 나누고난 나머지 값

        if(number1 == 0) { //나머지가 0이면 출력
            System.out.println("주사위의 합은 " + DiceSum + "이며 승리하셨습니다.");
        } else { //나머지가 0이 아니면 출력
            System.out.println("주사위의 합은 " + DiceSum + "이며 패배하셨습니다.");
        }
    }
}

 

+

동작은 잘 되지만

첫줄인 public class DiceTwo { 부분에서 오류가 있는 것 같은데 이유를 모르겠다.

->그냥 클릭 잘못해서 빨간 동그라미 생긴것ㅋㅋ

 

while이나 for, switch로도 시도해볼까?

'JABA' 카테고리의 다른 글

10. format 출력 printf  (0) 2023.03.24
9. Array 배열  (0) 2023.03.24
7. 랜덤 숫자  (0) 2023.03.21
6. While문  (0) 2023.03.21
5. Switch문  (0) 2023.03.21