हिंदी

What does the following program output to the monitor: int value = 0; int count = 1; value = count++; System.out.println("value:" + value "+ count:" + count);

Advertisements

प्रश्न

What does the following program output to the monitor:

int value = 0;
int count = 1;
value = count++;
System.out.println("value:" + value "+ count:" + count);
कोड लेखन
Advertisements

उत्तर

Initially, value = 0 and count = 1.

The statement value = count++; uses the post-increment operator (++). It assigns the original value of count to value and then increases count by 1.

Therefore,

  • value = 1
  • count = 2

However, the given System.out.println() statement contains a syntax error because the + operator is missing after value.

class PostIncrement
{
    public static void main(String[] args)
    {
        int value = 0;
        int count = 1;
        value = count++;
        System.out.println("value:" + value + " count:" + count);
    }
}

Output:

value:1 count:2

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
EXERCISE | Q 40. | पृष्ठ १३२
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×