Friday, May 31, 2013

Posted in My Programming Skill

Multiplication of Numbers


SOURCE CODE

class Multiplication {
public static void main(String args[]) { // start of main() method.
int a=9, b=12, c;  // initializing a & b of type integer.
c = a * b; //Multiplying a & b using "*" operator and storing in c.
System.out.println("Multiplication is : "+c);  // printing result.
} // end of main() method.
} // end of class.

OUTPUT

Multiplication is : 108




NOTE:-

 Instead of using
                c = a * b;
              System.out.println("Multiplication is : "+c);
you can use following single line of code

                System.out.println("Multiplication is : "+(a*b));
If you want to use above single line then you don't have to declare the third variable i.e. c.
You can multiply multiple numbers at a time.
Posted in My Programming Skill

Subtraction of Numbers


SOURCE CODE

class Subtraction {
public static void main(String args[]) { // start of main() method.
int a=10, b=14, c;  // initializing a & b of type integer.
c = a - b; //subtracting b from a using "-" operator and storing in c.
System.out.println("Subtraction is : "+c);  // printing result
} // end of main() method.
} // end of class.


OUTPUT

Subtraction is : -4




NOTE:-

   Instead of using
                c = a - b;
              System.out.println("Subtraction is : "+c);
you can use following single line of code

                System.out.println("Subtraction is : "+(a-b));
If you want to use above single line instead of those two then you don't have to declare the third variable i.e. c.


Posted in My Programming Skill

Sum Of Two Numbers

SOURCE CODE

class addition {
public static void main(String args[]) { // start of main() method.
    int a=10, b=14, c; // initializing a & b of type integer.
    c = a + b; // adding a & b using "+" operator and storing in c.
    System.out.println("Addition : "+c);     // printing result
}         // ending of main() method.
}      // end of the class.


OUTPUT

Addition : 24






NOTE:-
   Instead of using
                c = a + b;
System.out.println("Addition : "+c);
you can use following single line of code

                System.out.println("Addition : "+(a+b));
If you want to use above single line then you don't need to declare the third variable i.e. c.
Posted in My Programming Skill

Operators in JAVA




Operators are the thing which operates on variable to produce results. They manipulate both the data and variables. JAVA provides wide variety of operators. Those are as follows:-

1)      Arithmetic Operators:-
These operators are used on mathematical expressions. These operators are as follows:-

Sr. No.
Operator
Meaning
Sample Program
1
+
Addition
2
-
Subtraction
3
*
Multiplication
4
/
Division
5
%
Modulus
6
+=
Addition Assignment
7
-=
Subtraction Assignment
8
*=
Multiplication Assignment
9
/=
Division Assignment
10
%=
Modulus Assignment
11
++
Increment
12
--
Decrement

2)      Bitwise Operators:-
These operators are operated on type int, long, short, char and byte. These operators operate on individual bit of operand. These operators are as follows:-

Sr. No.
Operator
Meaning
Sample Program
1
~
Bitwise NOT
2
&
Bitwise AND
Click HERE
3
|
Bitwise OR
Click HERE
4
^
Bitwise EXCLUSIVE OR (XOR)
Click HERE
5
&=
Bitwise AND Assignment
Click HERE
6
|=
Bitwise OR Assignment
Click HERE
7
^=
Bitwise EXCLUSIVE OR (XOR) Assignment
Click HERE
8
>> 
Shift right
Click HERE
9
>>> 
Shift right zero fill
Click HERE
10
>>=
Shift right Assignment
Click HERE
11
>>>=
Shift right zero fill Assignment
Click HERE
12
<< 
Shift left
Click HERE
13
<<=
Shift left Assignment
Click HERE

3)      Relational Operators:-
These operators used to decide the relation between the operands. These operators are as follows:-

Sr. No.
Operator
Meaning
Sample Program
1
==
Equal to
Click HERE
2
!=
Not equal to
Click HERE
3
> 
Greater than
Click HERE
4
>=
Greater than or equal to
Click HERE
5
< 
Less than
Click HERE
6
<=
Less than or equal to
Click HERE


4)      Logical Operators:-
Logical operators are used to combine operands. These operators are as follows:-

Sr. No.
Operator
Meaning
Sample Program
1
&&
Logical AND
Click HERE
2
||
Logical OR
Click HERE
3
!
Logical NOT
Click HERE
4
^
Logical XOR
Click HERE
5
?:
Ternary if - else
Click HERE

5)      Assignment Operators:-
These operators are used to assign a particular value to the operator or to check the value of particular operand.


Sr. No.
Operator
Meaning
Sample Program
1
=
Assign the value
Click HERE
2
==
Check the value
Click HERE
3
===
Check the value with case sensitive
Click HERE


    Translate

    Protected by Copyscape