73.6k views
3 votes
Give the output of the following program: public class Example { public static void main(String [] args) { int x =5; int y =0; y = x++; System.out.print(y); System.out.print(x); } }

User Adriena
by
8.3k points

1 Answer

4 votes

Answer:

Output of the following program is :56

Step-by-step explanation:

In the given code snippet, x is initialize with 5 and y is with 0.Then y=x++ statement will assign 5 to y and the increment the value of x,because x++ is a post increment operator.So the value of x will increase after this statement.First print statement will print the value of y i.e 5 and the next print statement will print the value of x i.e 6 without space.Therefore the Output will be 56.

User Yalian
by
7.9k points

Related questions

Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.