728x90
public class Ex05 { //버블정렬 회전 오름차순
public static void main(String[] args){
int[] number = new int[10];
for(int i=0;i<number.length;i++)
System.out.print(number[i] = (int)(Math.random()*10));
System.out.println();
boolean change = false;
for(int i=0; i<number.length;i++){ // 회전수
change = false;
for(int j=0; j<number.length-1-i; j++){
if(number[j] > number[j+1]){
int temp = number[j];
number[j] = number[j+1];
number[j+1] = temp;
change = true;
}
}
if(!change) break;
for(int k=0; k<number.length; k++)
System.out.print(number[k]);
System.out.println();
}
}
}
728x90
'JAVA > 예제' 카테고리의 다른 글
[JAVA] ch06-07. 배열 (Array) 7 (0) | 2017.08.22 |
---|---|
[JAVA] ch06-06. 배열 (Array) 6 (0) | 2017.08.22 |
[JAVA] ch06-04. 배열 (Array) 4 (0) | 2017.08.22 |
[JAVA] ch06-03. 배열 (Array) 3 (0) | 2017.08.22 |
[JAVA] ch06-02. 배열 (Array) 2 (0) | 2017.08.22 |
댓글