Archive for April, 2012


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

import javax.swing.JOptionPane;

/**
*
* @author Muhammad Khafid F
*/
public class bil_vibo {
public static void main(String[] args) {
int deret=Integer.parseInt(JOptionPane.showInputDialog(“Masukkan berapa deret Fibonacci: “));
int a=0;
int b=1;
System.out.print(deret+” deret Fibonacci: ” );
for (int i=0;i<deret;i++){
System.out.print(a+” “);
a=a+b;
b=a-b;
}
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

import javax.swing.JOptionPane;

/**
*
* @author Muhammad Khafid F
*/
public class bil_prima {
public static void main(String[] args) {
String input =” “;

input = JOptionPane.showInputDialog(“Masukkan bilangan = “);
int a = Integer.parseInt(input);
int b, c, d;
b=1;
c=a-1;
if (a==2) {
JOptionPane.showMessageDialog(null,”Bilangan Prima “);
} else {
while (b<c) {
b++;
d=a%b;

if (d==0) {

JOptionPane.showMessageDialog(null,”Bukan Bilangan Prima “);
break;
} else if (d>0 && b==c) {
JOptionPane.showMessageDialog(null,”Bilangan Prima “);
}
}
}
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

import javax.swing.JOptionPane;

/**
*
* @author Muhammad Khafid F
*/
public class bil_pisitif_negatif {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int a = Integer.parseInt(JOptionPane.showInputDialog(“Masukkan angka ?”));

if(a >= 0){
JOptionPane.showMessageDialog(null, “Bilangan Positif”);
}
else{
JOptionPane.showMessageDialog(null, “Bilangan Negatif”);
}
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

import javax.swing.JOptionPane;

/**
*
* @author Muhammad Khafid F
*/
public class bil_ganjil_genap {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String a = JOptionPane.showInputDialog(“Masukkan Angka”);
int aa = Integer.parseInt(a);

if(aa % 2 !=0){
JOptionPane.showMessageDialog(null,”Bilangan Ganjil”);
}
else{
JOptionPane.showMessageDialog(null, “Bilangan Genap”);
}
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

/**
*
* @author Muhammad Khafid F
*/
public class Array_MultiD {
public static void main(String[] args) {
int[][][] arr3 = {{{10,20,30},{40,50,60}},
{{11,21,31},{41,51,61}},
{{12,22,32},{42,52,62}}};      // ukuran 3 * 6 = 18

System.out.println(“Nilai arr3[0] : ” + arr3[0][0][0]);
System.out.println(“Nilai arr3[0] : ” + arr3[0][0][1]);
System.out.println(“Nilai arr3[0] : ” + arr3[0][0][2]);
System.out.println(“Nilai arr3[0] : ” + arr3[0][1][0]);
System.out.println(“Nilai arr3[0] : ” + arr3[0][1][1]);
System.out.println(“Nilai arr3[0] : ” + arr3[0][1][2]);

System.out.println(“Nilai arr3[1] : ” + arr3[1][0][0]);
System.out.println(“Nilai arr3[1] : ” + arr3[1][0][1]);
System.out.println(“Nilai arr3[1] : ” + arr3[1][0][2]);
System.out.println(“Nilai arr3[1] : ” + arr3[1][1][0]);
System.out.println(“Nilai arr3[1] : ” + arr3[1][1][1]);
System.out.println(“Nilai arr3[1] : ” + arr3[1][1][2]);

System.out.println(“Nilai arr3[2] : ” + arr3[2][0][0]);
System.out.println(“Nilai arr3[2] : ” + arr3[2][0][1]);
System.out.println(“Nilai arr3[2] : ” + arr3[2][0][2]);
System.out.println(“Nilai arr3[2] : ” + arr3[2][1][0]);
System.out.println(“Nilai arr3[2] : ” + arr3[2][1][1]);
System.out.println(“Nilai arr3[2] : ” + arr3[2][1][2]);
}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

/**
*
* @author Muhammad Khafid F
*/
public class Array2D {
public static void main(String[] args) {
int[][] arrx;              // Cara 1 Array 2 Dimensi
arrx = new int[3][3];

arrx[0][0] = 1;
arrx[0][1] = 2;
arrx[0][2] = 3;

arrx[1][0] = 4;
arrx[1][1] = 5;
arrx[1][2] = 6;

arrx[2][0] = 7;
arrx[2][1] = 8;
arrx[2][2] = 9;

System.out.println(“Nilai arrx[0] : ” + arrx[0][0]);
System.out.println(“Nilai arrx[0] : ” + arrx[0][1]);
System.out.println(“Nilai arrx[0] : ” + arrx[0][2]);
System.out.println(“Nilai arrx[1] : ” + arrx[1][0]);
System.out.println(“Nilai arrx[1] : ” + arrx[1][1]);
System.out.println(“Nilai arrx[1] : ” + arrx[1][2]);
System.out.println(“Nilai arrx[2] : ” + arrx[2][0]);
System.out.println(“Nilai arrx[2] : ” + arrx[2][1]);
System.out.println(“Nilai arrx[2] : ” + arrx[2][2]);

int[][] arry = {{10,20,30},{40,50,60},{70,80,90}}  ;      // Cara 2 Array 2 Dimensi dgn ukuran 3 * 3 = 9

System.out.println(“Nilai arry[0] : ” + arry[0][0]);
System.out.println(“Nilai arry[0] : ” + arry[0][1]);
System.out.println(“Nilai arry[0] : ” + arry[0][2]);
System.out.println(“Nilai arry[1] : ” + arry[1][0]);
System.out.println(“Nilai arry[1] : ” + arry[1][1]);
System.out.println(“Nilai arry[1] : ” + arry[1][2]);
System.out.println(“Nilai arry[2] : ” + arry[2][0]);
System.out.println(“Nilai arry[2] : ” + arry[2][1]);
System.out.println(“Nilai arry[2] : ” + arry[2][2]);

}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Source_Coding;

/**
*
* @author Muhammad Khafid F
*/
public class array {
public static void main(String[] args) {
String[] kota;
kota = new String[5];

// Mengisi elemen array
kota[0] = “Jakarta”;
kota[1] = “Bandung”;
kota[2] = “Semarang”;
kota[3] = “Medan”;
kota[4] = “Yogya”;

// Menampilkan elemen array
System.out.println(kota[0]);
System.out.println(kota[1]);
System.out.println(kota[2]);
System.out.println(kota[3]);
System.out.println(kota[4]);
}
}