You are on page 1of 7

1.

Program Untuk Menghitung Luas Lingkaran :


Compile CMD


Coding
import java.util.Scanner;
public class Luas_Lingkaran{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double phi = 3.14;
double r, luas;
System.out.println("======================");
System.out.println("Program Luas Lingkaran");
System.out.println("======================");
System.out.println("");
System.out.print("Masukkan Jari-Jari Lingkaran: ");
r = input.nextDouble();
System.out.println("");
luas = 0.5 * phi * r * r;
System.out.print("Luas Lingkaran = " + luas + "\n\n");
}
}




2. Menginput identitas penduduk(nik,nama,ttl,jenis kelamin,status,pekerjaan dan alamat) pada
pekerjaan buatlah menggunakan fungsi switch case dengan ketentuan, jika pilihan 1, maka
PNS,2.TNI/POLRI,3.WIRASWASTA4.PETANI,5.Dll
Compile CMD


Coding
import java.util.Scanner;
public class Inputan_identitas_P {
public static void main(String[] args) {
String nik,nama,TTL,jenis_kelamin,status,alamat;
int pekerjaan;
Scanner identitas = new Scanner (System.in);

System.out.println("Masukkan data data anda");
System.out.print("NIK : ");
nik=identitas.nextLine();

System.out.print("Nama : ");
nama=identitas.nextLine();

System.out.print("TTL : ");
TTL=identitas.nextLine();

System.out.print("Jenis_KEL: ");
jenis_kelamin= identitas.nextLine();

System.out.print("Status : ");
status= identitas.nextLine();

System.out.println("");
System.out.println(" 1.PNS");
System.out.println("------------- 2.TNI/POLRI");
System.out.println("| PEKERJAAN | >> 3.WIRASWASTA");
System.out.println("------------- 4.PETANI");
System.out.println(" 5.DLL");
System.out.println("");

System.out.print("Masukkan No.Urut Kerja : ");
pekerjaan = identitas.nextInt();

System.out.print("Alamat : ");
alamat = (identitas.next());

System.out.println("===========================================");
System.out.println(" Halo " + nama + ", ini adalah biodata anda :)");
System.out.println("===========================================");
System.out.println("NIK: "+nik);

System.out.println("Nama Lengkap: "+nama);
System.out.println("TTL: "+TTL);
System.out.println("jenis kelamin: "+jenis_kelamin);
System.out.println("status: "+status);

switch (pekerjaan) {
case 1:
System.out.println("pekerjaan: PNS");
break;
case 2:
System.out.println("pekerjaan: TNI/POLRI");
break;
case 3:
System.out.println("pekerjaan: WIRASWASTA");
break;
case 4:
System.out.println("pekerjaan: PETANI");
break;
case 5:
System.out.println("pekerjaan: dll");
break;
}
System.out.println("Alamat: "+alamat);
}
}

3. Pengurutan huruf { F, E, D, A, C, B}, menjadi {A,B,C,D,E,F}
Compile CMD


Coding
import java.util.Arrays;
public class PengurutanHuruf {
public static void main(String[] args) {

System.out.println("====================================");
System.out.println(":: PROGRAM JAVA MENGURUTKAN HURUF ::");
System.out.println("====================================");
System.out.println("");
System.out.println("Huruf Sebelum Diurutkan : ");
System.out.println("---------------------------");
char[] Huruf_Acak = {'F','E','D','A','C','B'};
String tampilan;
for (int Dedy = 0; Dedy < Huruf_Acak.length; Dedy++)
System.out.print (Huruf_Acak[Dedy] + " ");
System.out.println("\n");
Arrays.sort(Huruf_Acak);
System.out.println("");
System.out.println("Huruf Sesudah Diurutkan : ");
System.out.println("---------------------------");
for (int Dedy = 0; Dedy < Huruf_Acak.length; Dedy++)
System.out.print(Huruf_Acak[Dedy] + " ");
}}

5. Mengurutkan Bilangan Acak Berdasarkan Ascending Dan Descending
Compile CMD


Coding
import java.io.*;
import java.util.Scanner;
public class mengurutkan_bilangan_acak {
public static int[] A = new int[10];
public static void main(String[] args) {
System.out.println("======================================");
System.out.println(" Selamat Datang Di :");
System.out.println("PROGRAM JAVA MENGURUTKAN BILANGAN ACAK");
System.out.println("======================================");
Scanner s = new Scanner(System.in);
int a;
System.out.println();
System.out.print("Masukkan Bilangan Yg Akan Anda Urutkan :");
System.out.println("\n");
String cmd = "";
int x;
boolean KELUAR = false;
BufferedReader inputUser = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
try {
System.out.print("Bilangan ke - " + (i + 1) + " : ");
cmd = inputUser.readLine();
x = Integer.parseInt(cmd);
A[i] = x;
System.out.println("");
} catch (Exception e) {
System.out.println("Bilangan Yg Anda Masukkan Salah");
}
}
System.out.println("-------------------");
System.out.println("Sebelum Diurutkan :");
System.out.println("-------------------");
printA();
acsending();
System.out.println("-----------");
System.out.println("Acsending :");
System.out.println("-----------");
printB();
descending();
System.out.println("------------");
System.out.println("Descending :");
System.out.println("------------");
printA();
}
public static void printB() {
for (int i = 0; i < 10; i++) {
System.out.print("\t" + A[i]);
}
System.out.println("");
}
public static void printA() {
for (int i = 0; i < 10; i++) {
System.out.print("\t" + A[i]);
}
System.out.println("");
}
public static void acsending() {
for (int i = 1; i < 10; i++) {
for (int j = i; j < 10; j++) {
if (A[i - 1] > A[j]) {
int dummy = A[i - 1];
A[i - 1] = A[j];
A[j] = dummy;
}
}
}
}
public static void descending() {
for (int i = 1; i < 10; i++) {
for (int j = i; j < 10; j++) {
if (A[i - 1] < A[j]) {
int dummy = A[i - 1];
A[i - 1] = A[j];
A[j] = dummy;
}
}
}
}
}


6. fungsi dalam soure code/coding java
Statement If
Pernyataan kendali aliran if akan menguji sebuah keadaan, apakah keadaan tsb benar(true) atau
salah(false). Jika keadaan tsb true maka kumpulan pernyataan yang berkaitan akan di jalankan dan jika
false maka tidak di jalankan.
Statement ifelseif adalah pernyataan dalam bentuk kondisi di dalam else ada if. Statement if pada
bagian else dapat menjadi struktur if-else yang lain.