import java.io.*;
public class lat6{
public static void main(String Arg[]) throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP = Get.readLine();
System.out.print("Nama :");Nama = Get.readLine();
System.out.print("Kode :");str = Get.readLine();
Kdj=Integer.parseInt(str);
if(Kdj==1){
jbt="Direktur";gaji=5000000;
}else if(Kdj==2){
jbt="Wakil Direktur";gaji=4000000;
}else if(Kdj==3){
jbt="Bendahara";gaji=3000000;
}else if(Kdj==4){
jbt="Staf";gaji=2000000;
}else {
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("Jabatan :"+jbt);
System.out.println("Gaji :"+gaji);
System.out.println("Pajak :"+pajak);
System.out.println("Total :"+total);
}
}
dan lihat hasil nya dibawah ini
2. latihan 7 :
import java.io.*;
public class lat7{
public static void main(String Arg[]) throws IOException{
String str;String NIP;String Nama;String jbt;
double gaji=0;double pajak=0;double total=0;
int Kdj;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
System.out.print("NIP :");NIP = Get.readLine();
System.out.print("Nama :");Nama = Get.readLine();
System.out.print("Kode :");str = Get.readLine();
Kdj=Integer.parseInt(str);
switch(Kdj){
case 1 : jbt="Direktur";gaji=5000000;
break;
case 2 : jbt="Wakil Direktur";gaji=4000000;
break;
case 3 : jbt="Bendahara";gaji=3000000;
break;
case 4 : jbt="Staf";gaji=2000000;
default:
jbt="";gaji=0;
}
pajak=0.1*gaji;
total=gaji-pajak;
System.out.println("Jabatan :"+jbt);
System.out.println("Gaji :"+gaji);
System.out.println("Pajak :"+pajak);
System.out.println("Total :"+total);
}
}
lihat hasilnya dibawah ini
3. contoh Perulangan (loop)
loop2.java
class loop2{
public static void main(String Arg[]{
int i=1;
do(
System.out.println(i);
i++;
}While(i !=11);
}
}
class loop2{
public static void main(String Arg[]{
int i=1;
do(
System.out.println(i);
i++;
}While(i !=11);
}
}
hasilnya :
4. Untuk menghitung kubus
import java.io.*;
class loop4{
public static void main(String Arg[]) throws IOException {
int pil,l s, r, p;
double ls,vol;
String str;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
do{
System.out.println("Menu Utama");
System.out.printl("1.Hitung Volume Kubus");
System.out.println("2.Hitung Luas");
System.out.println("3.Hitung Luas Lingkaran");
System.out.println("4.Keluar Prograram");
System.out.print("Pilihan Anda:");str=Get.readLine();
pil=Integer.parseInt(str);
switch(pil){
case 1:
System.out.println("Menghitung Volume Kubus");
System.out.print("Sisi:");str=Get.readLine();
s=Integer.parseInt(str);
vol=s*s*s;
System.out.println("Menghitung Luas Persegi Panjang");
System.out.print("Lebar :");str=Get.readLine();
1=Integer.parseInt(str);
System.out.print("Panjang:");str=Get.readLine();
p=Integer.parseInt(str);
ls=p*l;
System.out.prinln("Luas Persegi Panjang:"+ls);
break;
case 3:
System.out.println("Menghitung Luas Lingkaran");
System.out.print("Jari Jari:");str=Get.readLine();
r=Integer.paseInt(str);
ls=3.14*r*r;
System.out.print("Luas Lingkaran:"+ls);
break;
}
str=Get.readLine();
}while(pil!=4);
}
}
class loop4{
public static void main(String Arg[]) throws IOException {
int pil,l s, r, p;
double ls,vol;
String str;
BufferedReader Get=new BufferedReader(new InputStreamReader(System.in));
do{
System.out.println("Menu Utama");
System.out.printl("1.Hitung Volume Kubus");
System.out.println("2.Hitung Luas");
System.out.println("3.Hitung Luas Lingkaran");
System.out.println("4.Keluar Prograram");
System.out.print("Pilihan Anda:");str=Get.readLine();
pil=Integer.parseInt(str);
switch(pil){
case 1:
System.out.println("Menghitung Volume Kubus");
System.out.print("Sisi:");str=Get.readLine();
s=Integer.parseInt(str);
vol=s*s*s;
System.out.println("Menghitung Luas Persegi Panjang");
System.out.print("Lebar :");str=Get.readLine();
1=Integer.parseInt(str);
System.out.print("Panjang:");str=Get.readLine();
p=Integer.parseInt(str);
ls=p*l;
System.out.prinln("Luas Persegi Panjang:"+ls);
break;
case 3:
System.out.println("Menghitung Luas Lingkaran");
System.out.print("Jari Jari:");str=Get.readLine();
r=Integer.paseInt(str);
ls=3.14*r*r;
System.out.print("Luas Lingkaran:"+ls);
break;
}
str=Get.readLine();
}while(pil!=4);
}
}
hasilnya :