random 3

[JAVA] 숫자 야구(while / Integer.parseInt)

//1. Scanner 열기 Scanner scan = new Scanner(System.in); //2. 지역 변수들 선언 int comNum[] = new int[3]; //컴퓨터가 결정한 숫자 int myNum[] = new int[3]; //유저가 결정한 숫자 int cnt = 0; //게임 횟수 //3. 컴퓨터가 결정한 랜덤 3가지 숫자를 중복되지 않게 추출 -> 한번 생성 //반복적으로 추출 => for, while for(int i=0; i 3 4 0.. // 0 0 0 -> 3 4 3 -> 3 4 4 -> 3 4 5.. } } } //시작문은 while문 위에 배치 (반복x) System.out.println("=====야구게임 시작====="); //4. 사용자의 수 입력받기 -> 반복 ..

JAVA/java 예시 2023.03.26

[JAVA] 가위바위보 게임(random, .equals)

✔ 가위바위보게임 만들기 1. 컴퓨터가 가위, 바위, 보 중 랜덤으로 선택 (0=가위, 1=바위, 2=보) 2. 내가 가위, 바위, 보 중에서 선택해서 입력 => 승 / 패 / 무승부의 결과를 출력 Scanner scan = new Scanner(System.in); int random = (int)(Math.random()*3); System.out.println("랜덤의 수: " + random); if(random == 0 ) { System.out.println("컴퓨터: 가위"); } else if (random == 1) { System.out.println("컴퓨터: 바위"); } else { System.out.println("컴퓨터: 보"); } System.out.println("가위 ..

JAVA/java 예시 2023.03.26

[JAVA] Math.method

Math.method : 수학적 기능을 하기 위한 클래스 double num1 = 5.623456; //Math.round : 정수가 나오는 반올림 (소수점을 선택하는 기능x) System.out.println(Math.round(num1)); // 결과는 6 //Math.ceil : 올림, Math.floor : 버림 System.out.println(Math.ceil(num1)); //나오는 자료형이 double // 결과는 6.0 System.out.println(Math.floor(num1)); // 결과는 5.0 //Math.max : 최대값, Math.min : 최소값 System.out.println(Math.max(5, 3)); // 결과는 5 System.out.println(Math.m..

JAVA/java 공부 2023.03.25