개발일기/팀스터디 및 프로젝트+면접 질응답 정리
팀 스터디 (4월 14일 금요일) 주제 2: 다른 숫자게임 만들기
민장미
2023. 4. 15. 21:52
두 명의 User 와 Computer 가 각각 랜덤으로 3개의 숫자를 부여 받은 후
3개의 숫자 중 큰 값을 도출 하여, 두 개의 큰 값을 비교 후 큰 사람이 승리. ( 이 날 배웠던 최대값 구하기 사용할 것)
Math클래스의 random과 max를 이용하는 것이 포인트
수업 다 끝나고 남아서 이것저것 더 기능을 넣고 싶었는데 ... 매번 복습하느라 잠부족에
운동도 안했더니 죽을거 같아서 30분만 더 하고 헬스 갔다가 집가서 기절
주말 내로 완성하는게 목표
package team;
import java.util.Scanner;
public class Game_2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("게임을 시작합니다. 1~100사이의 숫자 3개를 랜덤으로 부여받습니다. start 입력시 게임시작 합니다.");
String input = sc.nextLine();
input = "start";
// game:
while (input == "start") {
int my1 = (int) (Math.random() * 100) + 1; // 첫번째 랜덤의 수를 부여 받음; 1~100 사이,
int my2 = (int) (Math.random() * 100) + 1;
int my3 = (int) (Math.random() * 100) + 1;
int max_my = Math.max(Math.max(my1, my2), my3); // 내가 가진 수 3개의 가장 큰 수를 찾는다.
System.out.println("나의 숫자 : " + my1 + "," + my2 + "," + my3);
System.out.println("나의 가장 큰 숫자:" + max_my);
System.out.println();
int com1 = (int) (Math.random() * 100) + 1;
int com2 = (int) (Math.random() * 100) + 1;
int com3 = (int) (Math.random() * 100) + 1;
int max_com = Math.max(Math.max(com1, com2), com3); // 컴이 가진 수 3개의 가장 큰 수를 찾는다.
System.out.println("컴퓨터의 숫자 : " + com1 + "," + com2 + "," + com3);
System.out.println("컴퓨터의 가장 큰 숫자:" + max_com);
System.out.println();
int winner = Math.max(max_my, max_com);
if (winner == max_my) {
System.out.println("승리하셨습니다. 축하드립니다.");
break;
} else {
System.out.println("패배하셨습니다. 아쉽네요.");
break;
}
} // while
}
}