Home > Back-end >  The small white to solve
The small white to solve

Time:09-20

//there are as follows: an array of
//int [] old=,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5 {1}
//requirements will not be zero value into a new array

Int [] old=,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5 {1};

Int [] newa=new int [18].
Int j=0;
for(int i=0; i<=old. Length - 1. I++) {

If (old [I]!=0) {
Newa [j]=old [I];
j++;
System. The out. Println (" array elements: "+ newa [j]);//output old here [I] why can newa [j] all 0
}

CodePudding user response:

J++ is an output after the initialization of the new array elements, of course is 0,
Before you j++ output, it is not zero,

CodePudding user response:

j++;
System. The out. Println (" array elements: "+ newa [j]);
The two order just switch over
When you put the first number is not 0 in the newa subscript to zero position, but after j++ you visit is starting from 1 subscript
So you output number than you always write the index of the former one, the int type, the default is 0, so all of the output is zero,

CodePudding user response:

Oh I see

CodePudding user response:

Why not give score - problem solving
  • Related