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
The program provided demonstrates the difference between the prefix and postfix increment operators ... View full answer
Get step-by-step solutions from verified subject matter experts
