1.penjumlahan
2.pengurangan
3.perkalian
4.pembagian
5.modulus
Contoh
package com.example;
public class Main {
public static void main(String[] args) {
int variable1 = 11;
int variable2 = 5;
int hasil;
// penjumlahan
hasil = variable1 + variable2;
System.out.println(variable1 + " + " + variable2 + " = " + hasil);
// pengurangan
hasil = variable1 - variable2;
System.out.printf("%d - %d = %d \n",variable1,variable2,hasil);
// perkalian
hasil = variable1 * variable2;
System.out.printf("%d x %d = %d \n",variable1,variable2,hasil);
// pembagian
hasil = variable1 / variable2;
System.out.printf("%d : %d = %d \n",variable1,variable2,hasil);
/* pembagian hasilnya 0 karena bertipe data integer tidak ada koma (,)
hasilnya tidak akan bulat / konversi
*/
float a = 6;
float b = 5;
float hasilFloat;
hasilFloat = a / b;
System.out.println(a + " : " + b + " = " + hasilFloat);
// modulus akan menganbil nilai sisa
hasil = variable1 % variable2;
System.out.printf("%d %% %d = %d \n",variable1,variable2,hasil);
}
}