Methods: Operasi Aritmatika

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static void main(String[] args) { Main main = new Main(); System.out.println("Hasil penjumlahan: "+ main.calculate("add", 10, 3)); // tambah System.out.println("Hasil pengurangan: "+ main.calculate("sub", 10, 3)); // kurang System.out.println("Hasil perkalian : "+ main.calculate("mul", 10, 3)); // kali System.out.println("Hasil pembagian : "+ main.calculate("div", 10, 0)); // bagi } public int calculate(String type, int a, int b) { if(type.equalsIgnoreCase("add")) { // tambah return a + b; } else if(type.equalsIgnoreCase("sub")) { // kurang return a - b; } else if(type.equalsIgnoreCase("mul")) { // kali return a * b; } else if(type.equalsIgnoreCase("div")) { // bagi if(b != 0) { return a / b; } } return 0; } }
Editor Settings
Theme
Key bindings
Full width
Lines