/** 建议7 * 这波陷阱列害了 * @param args */ public class Demo { public static void main(String[] args) { int count = 0; int count2 = 0; int count3 = 0; for (int i = 0; i<10 ; i++) { count = count++;//自增的陷阱 无效 count2++;//有效 count3 = ++count3;//有效 System.out.println("自增的陷阱 count="+count+" count2="+count2+" count3="+count3); } } }
/*
自增的陷阱 count=0 count2=1 count3=1
自增的陷阱 count=0 count2=2 count3=2
自增的陷阱 count=0 count2=3 count3=3
自增的陷阱 count=0 count2=4 count3=4
自增的陷阱 count=0 count2=5 count3=5
自增的陷阱 count=0 count2=6 count3=6
自增的陷阱 count=0 count2=7 count3=7
自增的陷阱 count=0 count2=8 count3=8
自增的陷阱 count=0 count2=9 count3=9
自增的陷阱 count=0 count2=10 count3=10
*/