Friday, 13 November 2015

Java Tutorial : Java Assignment Operators


Click here to watch in Youtube :
https://www.youtube.com/watch?v=u9S40sDGyWs&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Assignment Operators
AssignmentOperatorDemo1.java
class AssignmentOperatorDemo1
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * Assigns value from right side operands to left side operand.
         */
        a = b;

        System.out.println("a = " + a);

    }
}
Output
a = 2
AssignmentOperatorDemo2.java
class AssignmentOperatorDemo2
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * Adds right operand to the left operand and assign the result to left.
         * 
         * a+=b is same as a=a+b
         */
        a += b;

        System.out.println("a = " + a);

    }
}
Output
a = 7
AssignmentOperatorDemo3.java
class AssignmentOperatorDemo3
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * subtracts right operand from the left operand and assign the result
         * to left operand.
         * 
         * a-=b is same as a=a-b
         */
        a -= b;

        System.out.println("a = " + a);

    }
}
Output
a = 3
AssignmentOperatorDemo4.java
class AssignmentOperatorDemo4
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * mutiply left operand with the right operand and assign the result to
         * left operand.
         * 
         * a*=b is same as a=a*b
         */
        a *= b;

        System.out.println("a = " + a);

    }
}
Output
a = 10
AssignmentOperatorDemo5.java
class AssignmentOperatorDemo5
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * Adds right operand to the left operand and assign the result to left.
         * 
         * same as a=a/b
         */
        a /= b;

        System.out.println("a = " + a);

    }
}
Output
a = 2
AssignmentOperatorDemo6.java
class AssignmentOperatorDemo6
{
    public static void main(String[] args)
    {

        int a = 5;
        int b = 2;

        /*
         * calculate modulus using two operands and assign the result to left
         * operand.
         * 
         * a%=b is same as a=a%b
         */
        a %= b;

        System.out.println("a = " + a);

    }
}
Output
a = 1
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/OperatorsDemoAssignmentApp.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OperatorsDemoAssignmentApp

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/e1afee1d6e12479b500465256b2025d133889626/BasicJava/OperatorsDemoAssignmentApp/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge