write a program single dimensional array x[ ] of 10 integer element arrange the array in ascending using selection sorting. Print it the array before and after sorting each array should be printed in single line
Answers
Answered by
3
class SelectionSort{
public static void main(String args[]){
int number[] = {4,5,3,8,1,0,7,9,6,2};
int tempo;
for(int i = 0;i < 9;i++){
int min = i;
for(int j = i+1;j<10;j++){
if(number[min] > number[j]){
min = j;
}
}
tempo = number[i];
number[i] = number[min];
number[min]=tempo;
}
for(int i = 0;i<10;i++){
System.out.print(number[i]);
}
}
}
Hope this helps,
ira.
Similar questions