#9 Assignment Operators in Java



#9 Assignment Operators in Java

#9 Assignment Operators in Java

In this lecture we are discussing:
1)Assignment operator
a) = is used to assign a value to a variable
b) += is used to assign a value to a variable by adding it to the existing value
c) -= is used to assign a value to a variable by subtracting it from the existing value

— there are many but in this lecture we discussing only some

e.g of =
int num1=11;
int num2=12;
int result = num1 + num2;
int result1=num1-num2;
int result2=num1*num2;
int result3=num1/num2;
e.g of +=
int num=1;
num +=1; = num = num+1;
num +=5; = num = num+5;

e.g of -=
int num2=2;
num -=1; num =num-1;
num -=5; num =num-5;

2)increment and decrement operator
— there are two type of increment and decrement operator
a) pre
b) post

— post increment and decrement operator
int num=1;
num++;
System.out.println(num); // 2
— this operator is known as post increment operator

num–;
System.out.println(num); //1
— this operator is know as post decrement operator

— pre increment and decrement operator
int num=2;
++num;
System.out.println(num);//3

–num;
System.out.println(num);//2

Difference between pre and post operator
e.g for that we take one example
int num=5;
System.out.println(num++); // 5 is print on console

int num1=5;
System.out.println(++num); //6 is printed on screen

in post
first assignment and then increment
e.g int num=5; int copy;
copy=num++; in this case first num=5 assign to copy then increment the num
copy value is 5;

in pre
first increment then assignment
e.g int num=5;
int copy;
copy = ++num;

in this case first increment num value from 5 to 6 then assign to copy.
copy value is 6;

Github repo : https://github.com/navinreddy20/Javacode.git

Java and Spring Framework For beginners with Spring Boot : – http://bit.ly/3LDMj8D

Java Tutorial for Beginners (2023) :- http://bit.ly/3yARVbN

Instagram : https://www.instagram.com/navinreddyofficial/
Linkedin : https://in.linkedin.com/in/navinreddy20
Discord : https://discord.gg/UrYda98D

More Learning :

Java – https://bit.ly/3xleOA2
Python :- https://bit.ly/3H0DYHx
Django :- https://bit.ly/3awMaD8
Spring Boot :- https://bit.ly/3aucCgB
Spring Framework :- https://bit.ly/3GRfxwe

Servlet & JSP :- https://bit.ly/3mh5CGz
Hibernate Tutorial :- https://bit.ly/3NWAKah
Rest API | Web Service Tutorial :- https://bit.ly/38RJCiy

Git :- https://bit.ly/3NUHB3V
JavaScript :- https://bit.ly/3mkcFys
Kotlin :- https://bit.ly/3GR2DOG

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
http://www.telusko.com/contactus

Comments are closed.