자바 이클립스 사용법 질문좀..

자바 이클립스 사용법 질문좀..

작성일 2017.10.05댓글 1건
    게시물 수정 , 삭제는 로그인 필요

c언어 할때는 비쥬얼스튜디오로 그냥 별 문제없이 쉽게쉽게 했는데요


이번에 자바를 공부하게 됐는데 자바는 이클립스를 쓰더라구요


c언어 할땐 친구꺼 복사 붙여넣기로 해도 컴파일 돼서 실행이 잘 됐는데


자바는 계속 오류나고 빨간밑줄 생기고 클래슨지 패키진지 그거 때문인거 같은데


import java.util.Random;

public class DiceTest {

   public static void main(String[] args) {


      Dice dice = new Dice();

      for (int i = 0; i < 5; i++) {


         dice.throwDice();

      }


      dice.printResult();

   }


}

class Dice {


   private Random random;

   private Integer[] resultArray1;


   private Integer[] resultArray2;

   private int gameCount;


   private int index;

   public Dice() {


      random = new Random();

      resultArray1 = new Integer[5];


      resultArray2 = new Integer[5];

   }


   public void printResult() {

      int result = 0;


      System.out.println("총 게임 횟수 : " + gameCount);

      for (int a : resultArray1) {


         result += a;

      }


      System.out.println("A 획득 점수 : " + result);

      result = 0;


      for (int a : resultArray2) {

         result += a;


      }

      System.out.println("B 획득 점수 : " + result);


   }

   public void throwDice() {


      gameCount++;

      int diceNum = random.nextInt(6) + 1;


      int diceNum2 = random.nextInt(6) + 1;

      if (diceNum == diceNum2) {


         throwDice();

         } else if (diceNum > diceNum2){


         resultArray1[index] = diceNum;

         resultArray2[index] = 0;


         index++;

         } else if (diceNum < diceNum2) {


         resultArray1[index] = 0;

         resultArray2[index] = diceNum2;


         index++;

      }


   }

}
이 프로그램을 실행시키고 싶은데 도대체 방법을 모르겠네요
패키지 파일 없이 클래스명과 파일명을 일치시키라는데 그것도 무슨말인지 모르겠네요;;
어떻게해야하죠?




#자바 이클립스 #자바 이클립스 설치 #자바 이클립스 다운로드 #자바 이클립스 사용법 #자바 이클립스 단축키 #자바 이클립스 글자 크기 #자바 이클립스 vscode #자바 이클립스 다크모드 #자바 이클립스 왼쪽 창 #자바 이클립스 인텔리제이

profile_image 익명 작성일 -

main 메소드(함수)를 포함하고 있는 class DiceTest  와 자바 파일명을 DiceTest.java 로 하고 나머지 클래스는 위에 붙여서 하면 됩니다.


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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.util.Random;
 
class Dice {
 
    private Random random;
 
    private Integer[] resultArray1;
 
    private Integer[] resultArray2;
 
    private int gameCount;
 
    private int index;
 
    public Dice() {
 
        random = new Random();
 
        resultArray1 = new Integer[5];
 
        resultArray2 = new Integer[5];
 
    }
 
    public void printResult() {
 
        int result = 0;
 
        System.out.println("총 게임 횟수 : " + gameCount);
 
        for (int a : resultArray1) {
 
            result += a;
 
        }
 
        System.out.println("A 획득 점수 : " + result);
 
        result = 0;
 
        for (int a : resultArray2) {
 
            result += a;
 
        }
 
        System.out.println("B 획득 점수 : " + result);
 
    }
 
    public void throwDice() {
 
        gameCount++;
 
        int diceNum = random.nextInt(6) + 1;
 
        int diceNum2 = random.nextInt(6) + 1;
 
        if (diceNum == diceNum2) {
 
            throwDice();
 
        } else if (diceNum > diceNum2) {
 
            resultArray1[index] = diceNum;
 
            resultArray2[index] = 0;
 
            index++;
 
        } else if (diceNum < diceNum2) {
 
            resultArray1[index] = 0;
 
            resultArray2[index] = diceNum2;
 
            index++;
 
        }
 
    }
 
}
 
public class DiceTest {
 
    public static void main(String[] args) {
 
        Dice dice = new Dice();
 
        for (int i = 0; i < 5; i++) {
 
            dice.throwDice();
 
        }
 
        dice.printResult();
 
    }
 
}

자바 이클립스 사용법 질문

... 불편한것도 있고... 차차 적응해가면 금방 익숙해지겠죠? ㅋㅋㅋ 어쨌든 간단하게나마 이클립스 사용법에 대해 알아보았어요. 이제 본격적으로 자바에 대한...

자바 이클립스 사용법 질문좀..

c언어 할때는 비쥬얼스튜디오로 그냥 별 문제없이 쉽게쉽게 했는데요 이번에 자바를 공부하게 됐는데 자바이클립스를...

자바 이클립스 사용법 질문좀..

c언어 할때는 비쥬얼스튜디오로 그냥 별 문제없이 쉽게쉽게 했는데요 이번에 자바를 공부하게 됐는데 자바이클립스를 쓰더라구요...

자바 이클립스 질문

자바 이클립스 실행할려 하면 아래 처럼 뜨는데 해결방법 알려주세요요 JVM 1.8이 설치되었는데, 버전이 호환이 안 된다고 합니다. JVM버전을 17 또는 그 이상으로...

자바이클립스 사용법 질문드립니다.

자바 자체를 아예 한번도 배운적이 없는데 tcp , udp 소켓프로그래밍 과제를 내주셨는데, java 파일만 주셨습니다. .java 파일을 이클립스에서 드래그로 열고 run...