There are the following procedures:
Package com.lk.b; Public class TEST5 { publicstaticvoid main (string[] args) { // TODO auto-generated Method stub for (int i=0;i<10;i++) New Integer (i); System.out.println ("Hello World");} }
There may be a lot of people think this is right, in fact you are wrong, this program is not compiled by the compiler, because the integer k = new integer (i) this sentence. The For loop may not use {}, but is limited to executing statements (where the variable life statement is not included), since the scope of the integer k in this code is scoped to the entire main method, resulting in a duplicate definition of the variable error. Therefore, errors occur at compile time. To correct this, just add a pair of curly braces and let the variable be declared inside the block. As follows:
1 Packagecom.lk.b;2 3 Public classTEST5 {4 5 Public Static voidMain (string[] args) {6 //TODO auto-generated Method Stub7 for(inti=0;i<10;i++){8Integer k =NewInteger (i);9 }TenSystem.out.println ("Hello World"); One } A -}
A small question about the for loop