/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package kalkulator;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author gaara
*/
public class Kalkulator {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
Scanner masuk = new Scanner(System.in);
DataInputStream msk = new DataInputStream(System.in);
double nilai_1, nilai_2;
double hasil=0;
char operator;
System.out.println("====================");
System.out.println("aplikasi kalkulator");
System.out.println("====================");
System.out.print("masukan nilai 1 : ");
nilai_1 = masuk.nextInt();
System.out.print("masukan nilai 2 : ");
nilai_2 = masuk.nextInt();
System.out.print("masukan operator : ");
operator = (char) msk.read();
switch (operator) {
case '+':
hasil = nilai_1 + nilai_2;
break;
case '-':
hasil = nilai_1 - nilai_2;
break;
case '*':
hasil = nilai_1 * nilai_2;
break;
case '/':
hasil = nilai_1 / nilai_2;
break;
default:
System.out.println("maaf anda kurang bejo");
} System.out.println("jadi hasilnya : " + nilai_1 + operator + nilai_2 + '=' + hasil);
}
}
Tidak ada komentar:
Posting Komentar