Haduh, lama nggak update blog. ini gan dan sist, contoh program terbaru java. Baru bisa update soalnya laptop ane lagi bermasalah gan. check it out.....
package Praktek1;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class KonversiBilangan {
static String name;//object
static int bilDes;//variabel
static String gender;//variabel kelamin
//fungsi / method rekursi
public static void Biner(int n) {
if (n > 1) {
Biner(n / 2);
}
System.out.print(n % 2);
}
public static void Hexa(int n) {
char[] daftarHexa = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
if (n > 1) {
Hexa(n / 16);
}
System.out.print(daftarHexa[n % 16]);
}
public static void Octal(int n) {
char[] daftarOctal = {'0', '1', '2', '3', '4', '5', '6', '7'};
if (n > 1) {
Octal(n / 8);
}
System.out.print(daftarOctal[n % 8]);
}
public static int inputDes() {
System.out.print("Masukkan Bilangan Desimal : ");
Scanner inputan = new Scanner(System.in);
bilDes = inputan.nextInt();
return bilDes;
}
public static void tampilBiner() {
inputDes();
System.out.print("the Biner is ");
Biner(bilDes);
}
public static void tampilHexa() {
inputDes();
System.out.print("the Hexa is ");
Hexa(bilDes);
}
public static void tampilOktal() {
inputDes();
System.out.print("the Octal is ");
Octal(bilDes);
}
public static int inpBil() {
System.out.println("\nWellcome .. ");
System.out.print("\nNo bil: "
+ "\n1. Biner \n2. Hexa \n3. Oktal \n4. Exit");
System.out.print("\nMasukkan Angka Menu = ");
Scanner inputan = new Scanner(System.in);
int pilmenu = inputan.nextInt();
return pilmenu;
}
public static void gender() {
gender = JOptionPane.showInputDialog("write your gender right here "
+ "(L / P)");
if ("L".equals(gender)) {
JOptionPane.showMessageDialog(null, "Wellcome boys "
+ name);
} else {
if ("P".equals(gender)) {
JOptionPane.showMessageDialog(null, "Wellcome girls "
+ name
);
} else {
JOptionPane.showMessageDialog(null, "sorry, but you must input all"
+ " just input again !");
gender();
}
}
}
public static void menU(int pil) {
System.out.println("\033");//clear screen
switch (pil) {
case 1:
tampilBiner();
break;
case 2:
tampilHexa();
break;
case 3:
tampilOktal();
break;
case 4:
System.out.println("good bye");
System.exit(0);
break;
default:
System.out.println("(Sorry, just input number between 1 - 4)");
break;
}
System.out.println("\033");//clear screen
}
public static void main(String[] args) {
name = JOptionPane.showInputDialog(null,"what's your name ? ");
while (true) {
gender();
do {
menU(inpBil());
} while (true);
}
}
}
Posting Komentar