Guess the output
public class Increment Decrement
Quiz
{
public static void main(String[] args)
{
int a=11, b=22, C;
C = a + b + a-- + + + + + + a + ++b:
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
}
}
Answers
Answer:
a=11
b=23
C=78
Explanation:
Your question has extra '+' before the third appearance of 'a'. If we consider 3 '+' only, the value of C comes out to be 78.
Answer:
The output after running this code is that is is and is
Explanation:
Increment and decrement operators in Java also are referred to as unary operators because they treat one operand. The increment operator (++) adds 1 to its operand and therefore the decrement operator (–) subtracts one.
Given .
It is also only if .
Now, we'll substitute the values within the above expression, we get
is used before the increment is used before the increment is used after incrementis used after decrement
is used before increment means one is added to , i.e.
is used before increment means one is added to , we get
is used after increment means one is added to , i.e.
is used after increment means one is added to , we get
Then we get
and
#SPJ3