-->

MEMBUAT KALKULATOR SEDERHANA DENGAN JAVA

import java.io.*;
public class calkulator{
public static void main (String[] args) {
try{
DataInputStream in = new DataInputStream(System.in);
System.out.println("Inputkan angka pertama = ");
int a = Integer.parseInt(in.readLine());
System.out.println("Inputkan angka kedua = ");
int b = Integer.parseInt(in.readLine());
System.out.println("1.Penjumlahan \n2.Pengurangan \n3.Perkalian \n4.pembagian");
System.out.print("Operasi yang di pilih = ");
int c = Integer.parseInt(in.readLine());
int x = 1;
do
{
x++;
}
while (x <= 50);
System.out.println("\nAnda menjalankan kalkulator sederhana");
if (c == 1)
{
int d = a+b;
System.out.println("Hasil penjumlahan = "+d);
}
else
if (c == 2)
{
int d = a-b;
System.out.println("Hasil pengurangan = "+d);
}
else
if (c == 3);
{
int d = a*b;
System.out.println("Hasil perkalian = "+d);
}
if (c == 4)
{
int d = a/b;
System.out.println("Hasil pembagian = "+d);
}
}
catch (Exception e)
{
System.out.println("Masukan angka!");
}
}

}


Posting Komentar