Sorting Array Angka Tertentu di Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication31;
import java.util.Scanner;
/**
*
* @author ANGGA
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner data=new Scanner(System.in);
int angka=0;

// memasukkan jumlah angka
System.out.print(“Masukkan Jumlah Angka : “);
int[] array=new int[data.nextInt()];
System.out.println(“—————————–“);
// memasukkan angka
for(int i=0;i<array.length;i++){
System.out.print(“Masukkan Angka Ke-“+(i+1)+” : “);
array[i]=data.nextInt();
if(array[i]>40)
angka++;
}

// memindah angka >40 ke array baru
int[] array40=new int[angka];
int index=0;
for(int i=0;i<array.length;i++){
if(array[i]>40){
array40[index]=array[i];
index++;
}
}

// sorting bubble
int sementara;
for(int i=0;i<array40.length;i++){
for(int j=0;j<array40.length-1;j++){
if(array40[j+1]<array40[j]){
sementara=array40[j];
array40[j]=array40[j+1];
array40[j+1]=sementara;
}
}
}

// cetak array
System.out.println(“—————————–\nHasil Sorting Angka >40 :”);
for(int i=0;i<array40.length;i++){
System.out.print(array40[i]+” “);
}
System.out.println();

}

}

Satu pemikiran pada “Sorting Array Angka Tertentu di Java

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s