2013-11-25 3 views

답변

0
int count = 0; 
for(int i = 0; i < myList.size(); i++){ 
    if(myList.get(i) > val1 && myList.get(i) < val2) 
     count ++ 
} 
0

다음은 올바른 길을 걷기위한 예입니다.

int count80to100=0; //Keeping track of other ranges is left as an exercise 
for(Integer value:list) //use an enhanced for loop (for convenience) 
{ 
    int i = value.intValue(); //get the value 
    if(i>=80 && i<=100) //check if it's in the right range 
     count80to100++; //increment the counter 
} 
+0

이 방법이 효과가있을 수 있습니다. 인쇄하려면 어떻게해야합니까? 예를 들어, JTextBox.setText (xxxxxx + "")? – user2984158

+0

JFrames를 사용하고 있다면 제대로 작동 할 것입니다. 그렇지 않으면 간단한'System.out.println (count80to100);만으로 충분할 것이다. –

1

저는 자바에서 시작한다고 가정합니다. 숙제 문제가 아닙니다. 이것이 사실이라면, 당신은 당신의 가치를 얻기 위해 아래의 방법을 사용할 수 있습니다 : 계산하면

public int count(List<Integer> nums, int startValue, int endValue) { 
    int counter = 0; 
    for(Integer num: nums) { 
     if((num.intValue()>=startValue) && (num.intValue()<=endValue)) 
      counter++; 
    } 
    return counter; 
} 

, 항상 당신이 포함되는 값을 의미하는 최종 조건을 고려합니다.

관련 문제