I. Perhitungan rerata
coding pada button proses :
private void RATA_RATAActionPerformed(java.awt.event.ActionEvent evt) {
String tulis=PERHITUNGAN.getText();
String []sementara=tulis.split(",");
int k=0;
int index=0;
double hasil=0;
while(k<sementara.length){
hasil=hasil+Integer.parseInt(sementara[index]);
k++;
index++;
}
hasil=hasil/sementara.length;
HASIL_RATA.setText("Nilai rata rata dari "+tulis+" adalah "+hasil+"\n"
+ "Kompleksitas waktu dari "+tulis+" adalah "+sementara.length);
}
II. Pencarian Nilai max dan min pada array
coding pada button proses :
private void MIN_MAXActionPerformed(java.awt.event.ActionEvent evt) {
String nilai=PERHITUNGAN1.getText();
String []a=nilai.split(",");
int n=a.length;
int k=0;
int max=0;
int min=Integer.parseInt(a[0]);
int index=0;
while (k<n){
if(max>Integer.parseInt(a[index])){
k++;
index++;
}else{
max=Integer.parseInt(a[index]);
k++;
index++;
}
}
hasil_max.setText(""+max);
k=0;
index=0;
while (k<n){
if(min<Integer.parseInt(a[index])){
k++;
index++;
}else{
min=Integer.parseInt(a[index]);
k++;
index++;
}
}
hasil_min.setText(""+min);
// TODO add your handling code here:
}
III. Sequential seach
coding pada button proses :
private void sequentialActionPerformed(java.awt.event.ActionEvent evt) {
String nilai= PERHITUNGAN2.getText();
String [] a=nilai.split(",") ;
String cari= text_cari.getText();
int index=0;
boolean c=false;
while(!c && index<a.length){
if(Integer.parseInt(cari)==Integer.parseInt(a[index])){
c=true;
}
index++;
}
if(c==true)
sequent.setText("KETEMU pada index ke "+(index+1));
else
sequent.setText("GAK KETEMU");
}
IV. Bynery Search
coding pada button proses :
private void binaryActionPerformed(java.awt.event.ActionEvent evt) {
String nilai=PERHITUNGAN6.getText();
String []a=nilai.split(",");
String b=text_cari4.getText();
int awal = 0;
int n=a.length;
int cari=Integer.parseInt(b);
int akhir = n - 1;
int tengah = (awal + akhir)/2;
while( awal <= akhir ){
if ( Integer.parseInt(a[tengah]) < cari )
awal=tengah + 1;
else if ( Integer.parseInt(a[tengah]) == cari ) {
bin.setText(cari + " DITEMUKAN PADA LOKASI INDEX KE " + (tengah + 1) + ".");
break;
}
else
akhir = tengah - 1;
tengah = (awal + akhir)/2;
}
if ( awal > akhir ){
bin.setText(" TIDAK DITEMUKAN");
}
}
V. Selection Short
coding pada button proses :
private void selection_sort1ActionPerformed(java.awt.event.ActionEvent evt) {
String nilai= PERHITUNGAN3.getText();
String [] a=nilai.split(",") ;
int []b=new int[a.length];
for (int i = 0; i < a.length; i++) {
b[i]=Integer.parseInt(a[i]);
}
for(int i=0; i<b.length; i++){
int index_of_min = i;
for(int y=i; y<b.length; y++){
if(b[index_of_min]>b[y])
index_of_min = y;
}
int temp = b[i];
b[i] = b[index_of_min];
b[index_of_min] = temp;
}
for (int i = 0; i < b.length; i++) {
System.out.println(""+b[i]);
}
String c="";
for (int i = 0; i < b.length; i++) {
if(i==b.length-1)
c +=""+b[i];
else
c+=""+b[i]+",";
}
HASIL_selection.setText("hasil pengurutan nya adalah "+c);
}
DOWNLOAD PROGRAM |
Posted by 06.19 and have
0
komentar
, Published at
Tidak ada komentar:
Posting Komentar