import java.io.*;
/**
*
* @author indha
*/
public class kalkulator {
public static void main(String args[])throws IOException{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
String aa,bb,opt;
double a,b,hasil;
System.out.print("input angka :");
aa=br.readLine();
a=Double.parseDouble(aa);//mengkonversi double ke string
System.out.print("input angka :");
bb=br.readLine();
b=Double.parseDouble(bb);
System.out.print("input operator =");
opt=br.readLine();
if(opt.equals("+")||opt.equals("tambah")){
hasil=Double.parseDouble(aa)+Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("-")||opt.equals("kurang")){
hasil=Double.parseDouble(aa)-Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("*")||opt.equals("kali")){
hasil=Double.parseDouble(aa)*Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("/")||opt.equals("bagi")){
hasil=Double.parseDouble(aa)/Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}else
System.out.println("hasil tidak ditemukan");
}
}
/**
*
* @author indha
*/
public class kalkulator {
public static void main(String args[])throws IOException{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
String aa,bb,opt;
double a,b,hasil;
System.out.print("input angka :");
aa=br.readLine();
a=Double.parseDouble(aa);//mengkonversi double ke string
System.out.print("input angka :");
bb=br.readLine();
b=Double.parseDouble(bb);
System.out.print("input operator =");
opt=br.readLine();
if(opt.equals("+")||opt.equals("tambah")){
hasil=Double.parseDouble(aa)+Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("-")||opt.equals("kurang")){
hasil=Double.parseDouble(aa)-Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("*")||opt.equals("kali")){
hasil=Double.parseDouble(aa)*Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}
else if(opt.equals("/")||opt.equals("bagi")){
hasil=Double.parseDouble(aa)/Double.parseDouble(bb);
System.out.println("hasilnya ="+hasil);
}else
System.out.println("hasil tidak ditemukan");
}
}
untuk input operator bisa juga menggunakan kata "tambah","kali","bagi","kurang"
semoga bermanfaat buat kalian yang lagi belajar java...
23.34
0 komentar:
Posting Komentar