[Tutorial 5] Basic Operator Di dalam Java

Thursday 16 October 2014

Salam guys,

Kali ini kita akan tengok basic operator or biase orang panggil Arithmetic Operators di dalam Java.


Jenis Operator:

 

Penambahan  [ + ]

Walaupun senang still kene explain kat juga.Dimana untuk menambah 1 variable kepada variable yang lain.

contoh:

   
 int value1 = 10;  
 int value2 = 20;  
   
 System.out.println(value1 + value2);  

output: 30

OR:

   
 int value1 = 10;  
 int value2 = 20;  
 int total;  
   
 total = 10 + 20;  
   
 System.out.println(total);  

output: 30

Penolakan  [ - ]

Penolakan antara 1 variable or variable yang lain.


contoh:


   
 int value1 = 20;  
 int value2 = 10;  
   
 System.out.println(value1 - value2);  
  
output: 10

Pembagian [ / ] 

contoh:

   
 int value1 = 10;  
 int value2 = 2;  
   
 System.out.println(value1 / value2);  

Darab[ * ]

contoh:

   
 int value1 = 10;  
 int value2 = 2;  
   
 System.out.println(value1 * value2);  



No comments:

Post a Comment