Friday, May 18, 2012
Error Handling Source Code..
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package struktur.data;
import java.lang.reflect.Array;
import java.util.Arrays;
import javax.swing.JOptionPane;
/**
*
* @author Fajar
*/
class larik{int n = 6;
int j[] = new int [6];
// Inisialisasi Array
void isiArray() {
for (int l = 0; l < n; l++){
int h = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Nilai Array"));
j[l] = h;
}
for (int d =0; d<j.length; d++ ){
System.out.println(j[d]); }
}
// Sorting
void sortingArray(){
for (int i = 1; i < n; i++){
for (int g = 0; g < i; g++){
if (j[i]< j[g]){
int temp,var;
temp = j[i];
var = j[g];
j[i] = var;
j[g] = temp;
}
}
System.out.println(" ");
for (int f = 1; f <= j.length; f++){
System.out.println("Perpindahan Ke "+f);
for (int r = 0; r < n; r++){
System.out.println(j[r]);
}
System.out.println(" ");
}}
}
// Searching
void searchingArray (){
int low = j[0];
int tinggi = j.length;
int mid = low+tinggi/2;
int y = 0;
int key = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Angka yg ingin dicari"));
int numb = 0;
int u =0;
for(int r = 0; r <= j.length; r++){
try {
if (key >=mid){
for (int t = mid; t<n; t++){
if (key == j[t]){
JOptionPane.showMessageDialog(null, "data yang anda cari ditemukan pada indeks ke "+t);
System.out.println("data yang anda cari ditemukan pada indeks ke "+t);
t = n;}
u = 1;
r = r+j.length;
}
for (int t = 0; t<n; t++){
if (key == j[t]){
JOptionPane.showMessageDialog(null, "data yang anda cari ditemukan pada indeks ke "+t);
System.out.println("data yang anda cari ditemukan pada indeks ke "+t);
t = n;}
u = 1;
r = r+j.length;
}
}
else if (key < mid){
for (int t = 0; t<mid; t++){
y = key;
if (key == j[t]){
JOptionPane.showMessageDialog(null, "data yang anda cari ditemukan pada indeks ke "+t);
System.out.println("data yang anda cari ditemukan pada indeks ke "+t);
t = n;
u = 1;
r = r+j.length;
}
}
}
}
catch (Exception ex){
if (u<1){
JOptionPane.showMessageDialog(null, "data yang anda cari tidak ditemukan !!");
r = r+j.length;
}
}
}
}
}
public class Hybird_Search {
public static void main(String[] args){
larik a1;
a1 = new larik();
a1.isiArray();
a1.sortingArray();
a1.searchingArray();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment