package Chapter05;
import java.util.Random;
import java.util.Scanner;
public class Exercise53 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("가위 바위 보를 입력하세요: ");
while (true) {
Random random = new Random();
int c = random.nextInt(3); //0부터 2까지의 랜덤한 수
String result = "";
String gamer = scanner.next();
String[] str = {"가위", "바위", "보"};
String computer = str[c] ;
if (gamer.equals(computer)) {
result = "비겼습니다.";
}else if (gamer.equals("가위") && computer.equals("보") || gamer.equals("바위") && computer.equals("가위") || gamer.equals("보") && computer.equals("바위")){
result = "게이머 승리!";
}else {
result = "인공지능 컴퓨터 승리!";
}
System.out.println("게이머: " + gamer);
System.out.println("인공지능 컴퓨터: " + str[c]);
System.out.println("결과: " + result);
}
}
}
'Java > 과제' 카테고리의 다른 글
chapter06) 클래스 example - Circle (0) | 2022.08.23 |
---|---|
chapter05) 참조타입 example - 주사위를 던져서 각 면이 나오는 횟수를 출력하는 프로그램 (0) | 2022.08.17 |
chapter05) 참조타입 example - 로또번호를 생성하는 프로그램 (0) | 2022.08.17 |
chapter05) 참조타입 example - 최댓값과 최솟값을 구하시오. (2) | 2022.08.17 |
chapter04) 조건문과 반복문 example - 랜덤 숫자 맞추는 게임 프로그램 (0) | 2022.08.10 |