Loop diagonally through two dimensional array

前端 未结 12 1327
刺人心
刺人心 2020-12-05 11:52

I wrote the following code to walk half the diagonals of an array:

String[][] b = [a,b,c]
               [d,e,f]
               [g,h,i];  

public void LoopD         


        
12条回答
  •  春和景丽
    2020-12-05 12:19

    Just help yourself, have a look at the indices you need to loop through:

    #1 (0,0)               -> a
    #2 (1,0)  (0,1)        -> bd
    #3 (2,0)  (1,1)  (0,2) -> gec
    #4 (2,1)  (1,2)        -> hf
    #5 (2,2)               -> i
    

    Look at the change of the indices in each iteration and create your algorithm. Not so difficult, so do your homework yourself ;)

提交回复
热议问题