PENJUMLAHAN, PENGURANGAN, PERKALIAN DAN PEMBAGIAN
class DemoMethod2 {
/* Membuat method berparameter penjumlahan,
* pengurangan, perkalian dan pembagian
*/
void penjumlahan(int a, int b){
System.out.println("Nilai " + a + " + " + b + " = " + (a+b));
}
void pengurangan(int a, int b){
System.out.println("Nilai " + a + " - " + b + " = " + (a-b));
}
void perkalian(int a, int b){
System.out.println("Nilai " + a + " x " + b + " = " + (a*b));
}
void pembagian(int a, int b){
System.out.println("Nilai " + a + " / " + b + " = " + (a/b));
}
public static void main(String[] args) {
DemoMethod2 demoMethod = new DemoMethod2();
// memanggil method
demoMethod.penjumlahan(3, 5);
demoMethod.pengurangan(5, 4);
demoMethod.perkalian(4, 5);
demoMethod.pembagian(10, 2);
}
}