Arrays and enhanced for loops?

后端 未结 6 550
闹比i
闹比i 2021-01-22 15:19

Can someone please explain what is going on in this method?

class test{  
public static void main(String args[])
{
   int[] x = new int[4]; 
   int[] xy = new i         


        
6条回答
  •  花落未央
    2021-01-22 15:47

    You can use the for-loop instead:

    for(int i = 0 ; x.length > i; i ++) { 
    xy[i] += 1;
    }
    

    If you want to still use for each then here is the example

    a[]={1,2,3,4};
    for(int i:a)
    {
    println(i);
    }
    

    Hope it helps!

提交回复
热议问题