berikut ini adalah source codenya :
import jeliot.io.*;
public class MyClass{
static int data[]=new int[8];
static int kepala;
static int ekor;
static void create(){
kepala=ekor=-1;
}
static int isEmpty(){
if(ekor==-1){
return 1;
}else{
return 0;
}
static int isFull(){
if(ekor==8-1){
return 1;
}else{
return 0;
}
}
static void insert(int isi){
if(isEmpty()==1){
kepala=ekor=0;
data[ekor]=isi;
System.out.println(data[ekor]+" Behasil di tambah");
}else if(isFull()==0){
ekor++;
data[ekor]=isi;
System.out.println(data[ekor]+" Behasil di tambah");
}
}
static void print(){
if(isEmpty()==0){
System.out.println("Data yang ada :");
for(int i=kepala;i<=ekor;i++){
System.out.println(data[i]);
}
}else{
System.out.println("Data masih kosong!");
}
}
static void clear(){
kepala=ekor=-1;
System.out.println("Data berhasil dikosongkan !");
}
public static void main() {
int menu;
int a;
create();
do{
System.out.println("1. Insert");
System.out.println("2. Clear");
System.out.println("3. Print");
System.out.println("4. Exit");
System.out.print("Pilih Menu : ");
menu=Input.readInt();
switch(menu){
case 1: System.out.print("Masukkan data : ");
a=Input.readInt();
insert(a);break;
case 2: clear();
break;
case 3: print();
System.out.println();
break;
}
} while(menu!=4);
}
}
Selamat mencoba & semoga bermanfaat.......
0 komentar:
Posting Komentar