Bubble Sort Asscending dan Desscending di Java

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

package bubblesortsimple;
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 temporary;

System.out.print(“===================\n||PROGRAM SORTING||\n===================\nMasukkan Jumlah Angka Yang Akan diSorting : “);
int jumlah=data.nextInt();
System.out.println(“““““““““““““““““““““““`”);
int[] array=new int[jumlah];
for(int i=0;i<array.length;i++){
System.out.print(“Masukkan Angka ke “+(i+1)+” : “);
int angka=data.nextInt();
array[i]=angka;
}

// sorting asscending
for(int i=0;i<array.length-1;i++){
for(int j=0;j<array.length-1;j++){
if(array[j+1]<array[j]){
temporary=array[j];
array[j]=array[j+1];
array[j+1]=temporary;
}
}
}

System.out.println(“_________________________________________\nHasil Angka Setelah diSorting Asscending:”);
for(int i=0;i<array.length;i++){
System.out.print(array[i]+”  “);
}

// sorting Desscending
for(int i=0;i<array.length-1;i++){
for(int j=0;j<array.length-1;j++){
if(array[j+1]>array[j]){
temporary=array[j];
array[j]=array[j+1];
array[j+1]=temporary;
}
}
}
System.out.println();
System.out.println(“_________________________________________\nHasil Angka Setelah diSorting Desscending:”);
for(int i=0;i<array.length;i++){
System.out.print(array[i]+”  “);
}
System.out.println();
}

}

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