IT 개발노트

숫자맞추기 게임 본문

기초튼튼/JAVA

숫자맞추기 게임

limsungju 2019. 2. 18. 15:18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package Java.sungju.JavaTestProject;
 
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Iterator;
 
public class MainClass {
    public static void main(String[] args) {
        int put, num, num2, cnt=0, maxRound=0, maxScore=0, minRound=0, minScore=0;
        boolean bool = true;
        ArrayList<Integer> arr = new ArrayList<Integer>();
        Scanner sc = new Scanner(System.in);
        
        while(bool) {
            System.out.println("1.게임시작");
            System.out.println("2.게임전적");
            System.out.println("3.게임끝내기");
            System.out.print(">>> ");
            put = sc.nextInt();
            switch(put) {
            case 1:
                num2 = (int)(Math.random()*100+1);
                while(bool) {
                System.out.print("수를 입력하세요 : ");
                num = sc.nextInt();
                if(num2>num) {
                    System.out.println("Up");
                    cnt++;
                } else if(num2<num) {
                    System.out.println("Down");
                    cnt++;
                } else {
                    System.out.println("정답입니다!!!");
                    cnt++;
                    arr.add(cnt);
                    cnt = 0;
                    bool = false;
                }
                }
                bool = true;
                break;
            
            case 2:
                int n;
                ArrayList<Integer> L = new ArrayList<Integer>();
                int max;
                Scanner in = new Scanner(System.in);
                System.out.println("Enter Size of Array List");
                n = in.nextInt();
                System.out.println("Enter elements in Array List");
 
                for (int i = 0; i < n; i++) {
                    L.add(in.nextInt());
                }
 
                max = L.get(0);
 
                for (int i = 0; i < L.size(); i++) {
                    if (L.get(i) > max) {
                        max = L.get(i);
                    }
                }
 
                System.out.println("Max Element: " + max);
                in.close();
                
                break;
                
            case 3:
                System.out.println("게임을 종료합니다.");
                break;
            }
        }
    }
}
cs


'기초튼튼 > JAVA' 카테고리의 다른 글

TIME 예제(현재시간부터 일정 시간표시하기)  (0) 2019.02.19
프로세스 호출 예제  (0) 2019.02.19
제네릭스(Generics)  (0) 2019.02.12
스레드  (0) 2019.02.10
JAVA 입출력(I/O) 알아보기  (0) 2019.02.10