๋ฐ์ํ
์ ์ฌ๋ฌธ์
- ์ค๋ฆ์ฐจ์ ๋ฌธ์
- ๋ด๋ฆผ์ฐจ์ ๋ฌธ์
๋ชฉํ
์ฝ๋
- for ๋ฌธ ์ฌ์ฉ
- ๊ธฐ๋ณธ sort ์ ๋ ฌ ๋ฉ์๋ ์ฌ์ฉ
package JavaFestival;
import java.util.Arrays;
import java.util.Scanner;
public class test3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
for(int i = 0; i < arr.length ; i ++) {
System.out.printf("%d๋ฒ์งธ ์ ์
๋ ฅ: ",(i+1));
arr[i] = sc.nextInt();
System.out.println();
}
for(int i = 0; i< arr.length ; i++) {
for(int j = 0; j < arr.length-1 ; j++) {
if(arr[j]>arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
package JavaFestival;
import java.util.Arrays;
import java.util.Scanner;
public class test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[5];
for(int i = 0; i < arr.length ; i ++) {
System.out.printf("%d๋ฒ์งธ ์ ์
๋ ฅ: ",(i+1));
arr[i] = sc.nextInt();
System.out.println();
}
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
}
๊ฒฐ๊ณผ
1๋ฒ์งธ ์ ์
๋ ฅ: 12
2๋ฒ์งธ ์ ์
๋ ฅ: 10
3๋ฒ์งธ ์ ์
๋ ฅ: 7
4๋ฒ์งธ ์ ์
๋ ฅ: 19
5๋ฒ์งธ ์ ์
๋ ฅ: 4
[4, 7, 10, 12, 19]
๋ฐ์ํ