Created
February 10, 2019 11:55
-
-
Save bratawisnu/0125b7c0eb992e29ab496a6dd6bd13ab to your computer and use it in GitHub Desktop.
kalkulator sederhana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package brata.com; | |
import java.util.Scanner; | |
public class kalkulator { | |
static float total = 0, bil1 = 1, bil2 = 1; | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
while(bil2 != 0 & bil1 != 0){ | |
System.out.println("\nKalkulator Sederhana"); | |
System.out.println("1.Penjumlahan"); | |
System.out.println("2.Pengurangan"); | |
System.out.println("3.Perkalian"); | |
System.out.println("4.Pembagian"); | |
System.out.print("Masukan Pilihan Anda = "); | |
int pilihan = input.nextInt(); | |
switch(pilihan){ | |
case 1: | |
InputBilangan(); | |
System.out.println( + bil1 + " + " + bil2 ); | |
System.out.print("Hasilnya = "); | |
total = bil1 + bil2; | |
System.out.println(total); | |
break; | |
case 2: | |
InputBilangan(); | |
System.out.println( + bil1 + " - " + bil2 ); | |
System.out.print("Hasilnya = "); | |
total = bil1 - bil2; | |
System.out.println(total); | |
break; | |
case 3: | |
InputBilangan(); | |
System.out.println( + bil1 + " x " + bil2 ); | |
System.out.print("Hasilnya = "); | |
total = bil1 * bil2; | |
System.out.println(total); | |
break; | |
case 4: | |
InputBilangan(); | |
System.out.println( + bil1 + " : " + bil2 ); | |
System.out.print("Hasilnya = "); | |
total = bil1 / bil2; | |
System.out.println(total); | |
break; | |
default: | |
System.out.println("============================"); | |
System.out.println("Anda harus mengisi angka\n\n"); | |
} | |
} | |
} | |
private static void InputBilangan() { | |
Scanner input = new Scanner(System.in); | |
System.out.print("Masukan Bilangan Ke-1 = "); | |
bil1 = input.nextFloat(); | |
System.out.print("Masukan Bilangan Ke-2 = "); | |
bil2 = input.nextFloat(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment