Sabtu, Juni 12, 2010

Syntax kalkulator sederhana dengan Java

import java.io.*;

public class
Kalkulator
{
public static
void main(String [] args)
{
try{

DataInputStream in = new DataInputStream (System.in);
System.out.print("Inputkan angka pertama = ");
int a = Integer.parseInt(in.readLine());
System.out.print("Inputkan angka kedua = ");
int b = Integer.parseInt(in.readLine());
System.out.println("1.Penjumlahan \n2.Pengurangan \n3.Perkalian");
System.out.print("Mode operasi yang dipilih = ");
int c = Integer.parseInt(in.readLine());

int x = 1;
do
{
System.out.println("Loading.............................");

x++;
}
while (
x <= 50);

//System.out.println("\n\nMaaf mikir nya lama...");
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);
}
}
catch (
Exception e)
{
System.out.println("Masukkan angka!!!");
}
}
}

0 komentar:

Posting Komentar