Kalkulator (sangat) Sederhana Dengan Java / NetBeans
Berikut merupakan contoh program Kalkulator Sederhana menggunakan Pemrograman Java dengan IDE NetBeans. Sangat sederhana, menggunakan BufferedReader.
package smkprogdas;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author ardan7779
*/
public class InputBufferedReader {
public static void main(String args[]) throws IOException {
BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Kalkulator Sederhana");
System.out.println("==============");
int a, b, hasil = 0;
String operator;
System.out.print("Masukan Nilai pertama: ");
a = Integer.parseInt(ob.readLine());
System.out.print("Masukan Operator Aritmatika: ");
operator = ob.readLine();
System.out.print("Masukan Nilai kedua: ");
b = Integer.parseInt(ob.readLine());
switch (operator) {
case "+":
hasil = a + b;
break;
case "-":
hasil = a - b;
break;
case ":":
case "/":
hasil = a / b;
break;
case "*":
case "x":
hasil = a * b;
break;
default:
System.out.println("Ada yang keliru..!");
System.exit(0);
}
System.out.println("Hasil dari " + a + " " + operator + " " + b + " Adalah: "+hasil);
System.exit(0);
}
}