배열을 강조 정렬하고 배열 요소를 계산하려고 시도했습니다. 누락 된 것을 찾도록 도와주세요. 여러 번 디버깅했습니다. 여기에 내 코드와 출력이있다. 여기에 기능 여기배열 정렬 및 해당 요소 계산
Sorting(num, i, count);
}
public static void Sorting(int[] sort, int a, int con){
if (a<0) return;
/*am sorting the array here*/
Arrays.sort(sort);
int j, count=0;
for(j=0; j<con; j++){
if(sort[a]==sort[j])
count++;
}
System.out.println(sort[a]+" occurs "+count+" times");
Sorting(sort, a-1, con);
}
}
를 호출 덕분에
package habeeb;
import java.util.*;
public class Habeeb {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] num = new int[30];
int i, count=0;
System.out.println("Enter the integers between 1 and 100");
for(i=0; i<num.length; i++){
num[i]= input.nextInt();
if(num[i]==0)
break;
count++;
}
출력입니다 :
run:
Enter the integers between 1 and 100
2
5
4
8
1
6
0
0 occurs 6 times
0 occurs 6 times
0 occurs 6 times
0 occurs 6 times
0 occurs 6 times
0 occurs 6 times
0 occurs 6 times
괄호 (1 개의 경우에도)를 다시 입력하고 계산하십시오. – sp00m
주어진 배열에서 숫자의 발생 횟수를 계산 하시겠습니까? 예? –
예, 그렇습니다. 그리고 그것은 억지력이 있어야합니다. –