Question: Sample for Prefix vs Postfix Increment Operator //RUN THIS CODE to help you understand the difference between the prefix and postfix increment operator public class


 


Sample for Prefix vs Postfix Increment Operator

//RUN THIS CODE to help you understand the difference between the prefix and postfix increment operator

public class PrePostDemo

{

public static void main(String[] args)

{

int i = 3;

i++;

System.out.println(i); //prints out 4

++i;

System.out.println(); //prints out 5

System.out.println(++i); //prints out 6 -- increments then prints

System.out.println(i++); //prints out 6 -- prints then increments

System.out.println(i); //prints out 7 because previous line incremented i

}

}




Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The program provided demonstrates the difference between the prefix and postfix increment operators ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!