์์ค ์ฝ๋
package org.example;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] numbers = new int[20];
Arrays.fill(numbers, -1);
int numbersLastIndex = -1;
while (true) {
System.out.printf("์ซ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์(-1 : ์ข
๋ฃ) : ");
int num = sc.nextInt();
if (num == -1) {
System.out.println("์
๋ ฅ์ ์ข
๋ฃํฉ๋๋ค.");
break;
}
numbersLastIndex++;
numbers[numbersLastIndex] = num;
}
Arrays.sort(numbers);
StringBuilder sb = new StringBuilder();
for (int number : numbers) {
if (number == -1) continue;
if (sb.isEmpty() == false) {
sb.append(", ");
}
sb.append(number);
}
System.out.printf("์
๋ ฅํ ์ซ์(์ค๋ฆ์ฐจ์) : %s\n", sb.toString());
System.out.println("ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค.");
sc.close();
}
}
๊ฒฐ๊ณผ