I was working on a code and I came across this. How can I use for-each in the below mentioned code to perform the same as the loop show exactly below (two nested for loops):
String names[3] = {"A","B","C"}; int result[][] = calculate_exchange(calculate_matrix());//function call returns a 3x3 matrix /*for(int i[]:result){ for(int j:i){ if(j!=0){ System.out.println(names[]);//how do I use the i'th element? //names[i] gives an error(obviously!!!) } } }*/ for(int r=0;r<3;r++){//this loop works fine for(int c=0;c<3;c++){ if(result[r][c]!=0){ System.out.println(names[r]+"->"+names[c]+" = "+result[r][c]); } } } for(int i[]:result) makes i an array, then would it be possible to use for-each in this case?
PS:I have got my code working without using for-each, i am asking this just to satisfy my curiosity.