본문 바로가기
java&eclipse 코딩 알고리즘/20231204

RankTest2

by 몽상크리에이터 2023. 12. 13.

package k20231204;

 

public class RankTest2 {

 

public static void main(String[] args) {

 

int[] score = { 80, 100, 70, 100, 90, 84, 85 };

int[] rank = new int[score.length];

for (int i = 0; i < rank.length; i++) {

rank[i] = 1;

}

 

for (int i = 0; i < rank.length - 1; i++) {

for (int j = i + 1; j < score.length; j++) {

if (score[i] > score[j]) {

rank[j]++;

// i번째 점수가 크면 j번째 석차를 1증가 시키고 j번째 점수가 크면 i번째 석차를 1증가시킨다.

// 오름차순 석차를 계산하려면 부등호를 모두 반대로 변경하면 된다

} else if (score[i] < score[j]) {

rank[i]++;

}

}

}

for (int i = 0; i < rank.length; i++) {

System.out.printf("%3d점은 %d등 입니다.", score[i], rank[i]);

// 별점 출력, 10점 당 까만별 1개

for (int j = 0; j < score[i] / 10; j++) {

System.out.print("★");

}

// 5점 단위로 흰별을 출력한다.

if (score[i] % 10 >= 5) {

System.out.print("☆");

}

System.out.println();

}

 

}

 

}

'java&eclipse 코딩 알고리즘 > 20231204' 카테고리의 다른 글

StarTest  (0) 2023.12.13
SelectionSort  (0) 2023.12.13
RankTest  (0) 2023.12.13
PowerBallTest  (0) 2023.12.13
LottoTest2  (0) 2023.12.13