ini adalah salah satu contoh dari java class library:
import java.io.*;
public class pertemuan10_4{
public static void main(String[] args){
int a=0, b=0, pilih=0;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
pertemuan10_4 obj104 = new pertemuan10_4();
boolean ulang = true;
try{
System.out.println("Masukan 2 Buah Bilangan");
System.out.println("-----------------------");
System.out.print("A : "); a = Integer.parseInt(input.readLine());
System.out.print("B : "); b = Integer.parseInt(input.readLine());
while(ulang){
System.out.println("--------------------------");
System.out.println(">> Aritmatik 2 Bilangan <<");
System.out.println("--------------------------");
System.out.println("1. Tambah");
System.out.println("2. Kurang");
System.out.println("3. Kali");
System.out.println("4. Bagi");
System.out.println("5. Selesai");
System.out.println("--------------------------");
System.out.print("Masukan Pilihan : "); pilih = Integer.parseInt(input.readLine());
switch(pilih){
case 1:
obj104.tambah(a,b);
break;
case 2:
obj104.kurang(a,b);
break;
case 3:
obj104.kali(a,b);
break;
case 4:
obj104.bagi(a,b);
break;
case 5:
ulang=false;
break;
}
}
}
catch(Exception e){
}
}
void tambah(int a, int b){
int c = a + b;
System.out.println(c);
}
void kurang(int a, int b){
int c = a - b;
System.out.println(c);
}
void kali(int a, int b){
int c = a * b;
System.out.println(c);
}
void bagi(int a, int b){
int c = a / b;
System.out.println(c);
}
}
Tidak ada komentar:
Posting Komentar