Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Multidimensional array in JAVA

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39636
    samnizamani
    Member

    for(int i = 0; i < 3; i++){
    for(int j=0; j < 5; j++){
    nums[j] = (i+1)*(j+1);
    }
    }

    for(int x[] : nums) {
    for(int y : x) {
    System.out.println(“Value is: ” + y);
    sum += y;
    }
    }
    System.out.println(“Summation: ” + sum);
    }
    }
    The output from this program is shown here:
    Value is: 1
    Value is: 2
    Value is: 3
    Value is: 4
    Value is: 5
    Value is: 2
    Value is: 4
    Value is: 6
    Value is: 8
    Value is: 10
    Value is: 3
    Value is: 6
    Value is: 9
    Value is: 12
    Value is: 15
    Summation: 90

    Out put of this array seems to be confusing :(

    It should be something like this, 1, 4, 9 instead of 1,2,3
    what is actually happening?

    #109206
    wolfcry911
    Participant

    the output is correct
    the j for loop will finish looping before i is incremented and then j will loop again…

    edit// I’m curious why you don’t post this and other java questions in a java forum?

    #109207
    samnizamani
    Member

    I have posted in java forums, But haven’t been notified yet…

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.