Minggu, 27 Mei 2012
Java Binary Search dan Sequential Search
SearchingApp.java
public class SearchingApp {
public static void main(String[] args){
int jml = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Jumlah Data!"));
Searching data = new Searching(jml);
for(int i=0;i<jml;i++){
int isi = Integer.parseInt(JOptionPane.showInputDialog("Masukkan angka ke-"+(i+1)));
data.isi(isi);
}
System.out.println("Program Searching (sequential & binary)");
data.tampil();
int menu = Integer.parseInt(JOptionPane.showInputDialog("Searching\n1. sequential\n2. binary"));
switch(menu){
Circular Singel LinkedList
Node.java
public class Node {
public int angka;
public Node next;
public Node(int a){
this.angka = a;
}
public void printNode(){
System.out.println(angka);
}
}
LinkApp.java
public class LinkApp {
public static void main(String[] args){
LinkedList input user 10 angka
Node.java
public class Node {
int angka;
Node next;
Node(int data){
this.angka = data;
}
}
NodeListApp.java
public class NodeListApp {
public static void main(String[]args){
Minggu, 20 Mei 2012
Pencarian / Searching
public class SearchingApp {
public static void main(String[] args){
int aa = Integer.parseInt(JOptionPane.showInputDialog("Masukkan Jumlah Data!"));
Searching data = new Searching(aa);
for(int i=0;i<aa;i++){
String bb = JOptionPane.showInputDialog("Masukkan Kata ke-"+(i+1));
data.isi(bb);
}
data.tampil();
String cari = JOptionPane.showInputDialog("Masukkan kata yang dicari!");
int f = data.SeqSearch(cari);
if(f<0){
JOptionPane.showMessageDialog(null,"Maaf, Data tidak ditemukan");
}else{
JOptionPane.showMessageDialog(null,"Data ditemukan pada array ke-"+f);
Pengurutan / Sorting
public class Sorting {
private int[] a;
private int nElems;
public Sorting(int max)
{
a = new int[max];
nElems = 0;
}
public void isi(int value)
{
a[nElems] = value;
nElems++;
}
public void tampil()
{
for(int j=0; j<nElems; j++){
Minggu, 06 Mei 2012
Hirarki Class Hewan
HewanApp.java
public class HewanApp {
public static void main(String[] args) {
//bikin objek dulu
//Superclass//
Hewan superH = new Hewan();
//sub hewan//
HewanMamalia subMa = new HewanMamalia();
HewanUnggas subUng = new HewanUnggas();
HewanReptil subRep = new HewanReptil();
Array satu dimensi dan dua dimensi
public class Array1Dimensi {
public static void main(String[] args){
int bab[] = new int[10];
for(int i=0;i<10;i++){
bab[i]=i+1;
}
for(int i=0;i<10;i++){
System.out.println("array ke-"+i+" = "+bab[i]);
}
Langganan:
Postingan (Atom)