You refer the below code with comments:
int num=6;//num is 6 here
num=num+1;//num is 7 after this step
if (num>6)//num is greater than 6 ? YES, so below line will be executed
jTextField1.setText(Integer.toString(num));//It comes here & sets jTextField1 as 7
else
jTextField1.setText(Integer.toString(num+5));
In the first case as explained above, jTextField1 will be set as 7.
What would we use “num=7” or “num==7”?
num=7 is assignment of 7 to num variable
num==7 is used when you are checking a condition for num is 7 which simply returns true or false (you need to note that, == is equality operator in Java which is used to check if two values are equal or not)
I want to know if we use if(num==7) or if(num=7) ?
You never use num=7 during the condition check of if , while or for
I suggest you read here and understand the basics first.
6
solved If statement JAVA [closed]