/** * A Java problem. What is the output of this function. Alternately * put, wheat is the final value of the variable k (and kk)? * This all depends on when exactly the ++ happens and if the timing * of the increment is affected by things like function calls. * * All of this confusion is made passible by the fact that ++ is an * expression rather than a statement. * * @author gtowell * Created: Sep 2022 */ public class Order { public static void main(String[] args) { Order hw = new Order(); int j = 5; int k = hw.echo(j++) * hw.echo(j++); System.out.format(" k:%3d j:%3d\n", k, j); int jj = 5; int kk = jj++ * jj++; System.out.format("kk:%3d jj:%3d\n", kk, jj); } /** * Just print the value of the param and return it back * @param y a number * @return the number passed in */ public int echo(int y) { System.out.format("PARAM:%d\n", y); return y; } }