Home / Pemrograman / JAVA / Sorting Algorithms In Java Tutorial Belajar Pemrograman

Sorting Algorithms In Java Tutorial Belajar Pemrograman

Algoritma Sorting Data

Sorting Algorithms In Java tutorial
Sorting Algorithms In Java tutorial
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sortingdata;

/**
*
* @author eko rudiawan
*/
import java.io.*;

public class SortingData {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
int[] data = new int[10];
int[] ascending = new int[10];
int[] descending = new int[10];
int i;
int x; // menyimpan variabel sementara
String input;
BufferedReader dataInput = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Program Mengurutkan Bilangan Bulat");
System.out.println("Masukkan bilangan sebanyak 10 kali");
for (i = 0; i < 10; i++) {
System.out.print("a[" + i + "] = ");
try {
input = dataInput.readLine();
data[i] = Integer.parseInt(input);
} catch (NumberFormatException error) {
System.out.println("Input harus bilangan bulat");
}
}
System.out.print("Data Sebelum Disorting = ");
for (i = 0; i < 10; i++) {
System.out.print(data[i] + " ");
}
System.out.println("");

for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
if (data[j] < data[k]) {
x = data[j];
data[j] = data[k];
data[k] = x;
}
}
}
System.out.print("Data Ascending = ");
for (i = 0; i < 10; i++) {
System.out.print(data[i] + " ");
}
System.out.println("");
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
if (data[j] > data[k]) {
x = data[j];
data[j] = data[k];
data[k] = x;
}
}
}
System.out.print("Data Descending = ");
for (i = 0; i < 10; i++) {
System.out.print(data[i] + " ");
}
System.out.println("");
}
}

About Eko Rudiawan

Seorang lelaki yang punya ketertarikan dengan dunia elektronika dan robot yang saat ini sedang serius belajar tentang dunia bisnis dan internet marketing. My dream to be success technopreneur

Check Also

Palindrom Words Java

Palindrome Words Java Algorithm And Source Code

Palindrome Words Java /* * To change this template, choose Tools | Templates * and …

3 comments

  1. Salam dari harto, saya mau mencoba , tolong di email step by step , habis saya baru belajar , trims

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × two =