2013-11-15 2 views
0

이 내가 현재 가지고있는 것입니다 :테스트 점수를 누적하는 방법은 무엇입니까?

변수는 방법 지역이기 때문에 모든 값은 즉시 방법 종료와 같은 길을 잃을 것이다
private void EnterBtnActionPerformed(java.awt.event.ActionEvent evt) {           
    // TODO add your handling code here: 

    if (isValidData()) 
    { 
     int count = 0; 
     int score = Integer.parseInt(TestScoreTF.getText()); 
     int sumScore = 0; 
     int sumScores = sumScore += score; 
     count ++; 
     NumberFormat nf = NumberFormat.getInstance(); 
     NumberOfScoresTF.setText(nf.format(count)); 
     int avgScores = sumScores/count; 

     AverageScoresTF.setText(nf.format(avgScores)); 
    } 
+0

왜 'sumScore' 변수가 있습니까? 아무 목적도 가지고 있지 않습니다. –

+1

이 전체 상황'int sumScores = sumScore + = score;'는 유효한 코드 일 수 있지만 매우 드문 경우입니다 –

답변

2

. 메소드 호출간에 값을 "기억"해야하는 경우 클래스의 속성으로 sumScorecount을 선언하십시오.

관련 문제