3. ARITHMETIC OPERATORS

Welcome back to my third java tutorial.In last tutorial we are learning to run a program.Before that we have to know that why are we learning java.Whats make java one of the best programming language.Here are they.............
1.Simple
2.Secure
3.Portable
4.Object-oriented
5.Robust
6.Multithreaded
7.Architecture-neutral
8.Interpreted
9.High performance
10.Distributed
11.Dynamic

 Today we will learning arithmetic operators.
First of all we have to remember 

Name
Width
Range
int
32
-2,147,483,648 to 2,147,483,647
double
64
4.9e-324 to 1.8e+308
float
32
1.4e-045 to 3.4e+038
string
String



arithmetic operators

=
Assign value
==
equal
!=
Not equal
Less than
Greater than
<=
Less or equal
>=
Greater or equal
+
Addition
-
Subtraction
*
Multiplication
/
division
%
modulus
&&
and
||
or


now a simple program

create a class (I have named pavel);
(last tutorial i have seen you how to create a class.So i hope you can)


public class pavel {
      public static void main(String args[]){
     int sub,multi,div,add,mod;
     int i=8;
     int j=2;
     
     //now addition
     add=i+j;
      System.out.println("Subtraction of numbers : "+ add);
     //now Subtraction
     sub=i-j;
     System.out.println("Subtraction of numbers : "+ sub);
     //now Multiplication
     multi=i*j;
     System.out.println("Multiplication of numbers : "+ multi);
     //now division
     div=i/j;
     System.out.println("division of numbers : "+ div);
     //now modulus
     mod=i%j;
     System.out.println("modulus of numbers : "+ mod);
      }
}
result of the program is

Addition of numbers : 10
Subtraction of numbers : 6
Multiplication of numbers : 16
division of numbers : 4
modulus of numbers : 0

Here see we take 7 integer variable.initialized two variable i=8 and j=2;
here //(two backslash means that's a comment .it is not executed  )
add=i+j;
First we add i and j means (8+2) so it's result is 10.
System.out.println("Subtraction of numbers : "+ add);
Here in println we use '+' for adding .
sub=i-j;
secondly we subtract i and j (8-2) so result is 6
multi=i*j;
here we multiply i and j(8*2)so result is 16
div=i/j;
here we divided i with j(8/2)so result is 4
 mod=i%j;
here we modulus i with j(8%2)but 8 is divisible by 2. so result is 0
but if     i=9 and j=2
then     mod=i%j ;     equal 1.
or
    i=11 and j=3
then
    mod=i%j;             equal 2;

next tutorial we we learning more arithmetic operation with if-else statement.
Till then best of luck.

Penulis : Mostafij ~ Sebuah blog yang menyediakan berbagai macam informasi

Artikel 3. ARITHMETIC OPERATORS ini dipublish oleh Mostafij pada hari Tuesday, April 9, 2013. Semoga artikel ini dapat bermanfaat.Terimakasih atas kunjungan Anda silahkan tinggalkan komentar.sudah ada 0 komentar: di postingan 3. ARITHMETIC OPERATORS
 

0 comments:

Post a Comment