dengan menggunakan metode Selection
berbasis Java
*/
import java.util.Scanner;
public class selection {
public static void main(String[] args) {
int data[] = new int[100];
int index;
System.out.print("Masukkan banyak data : ");
Scanner varinput = new Scanner(System.in);
int n = varinput.nextInt();
for(int i=0;i<n;i++){
System.out.print("Data ke-"+(1+i)+" : ");
data[i] = varinput.nextInt();
}
for(int i=0;i<n-1;i++){
index=i;
for(int j=i+1;j<n;j++){
if(data[j]<data[index]){
index=j;
}
}
if(index != i){
int tempdata=data[i];
data[i] = data[index];
data[index] = tempdata;
}
}
for(int i=0;i<n;i++){
System.out.println(data[i]);
}
}
}
Output
0 Comments