https://github.com/ggleblanc2/arraysum
The code in this repository answers a Stack Overflow question that was closed
https://github.com/ggleblanc2/arraysum
java-8 loops
Last synced: about 2 months ago
JSON representation
The code in this repository answers a Stack Overflow question that was closed
- Host: GitHub
- URL: https://github.com/ggleblanc2/arraysum
- Owner: ggleblanc2
- Created: 2022-06-30T09:54:00.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-30T10:19:20.000Z (about 4 years ago)
- Last Synced: 2025-02-10T21:49:49.005Z (over 1 year ago)
- Topics: java-8, loops
- Language: Java
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ArraySum
The original question on [Stack Overflow](https://stackoverflow.com/questions/72805749/give-advice-on-the-2d-array-and-array-looping-in-java-please?noredirect=1#comment128607046_72805749) can be restated as follows.
Given a two-dimensional array, I wish to sum each 2 x 2 subarray and produce an output two-dimensional array. For example, if I have the folllowing 4 x 5 input array
50 45 47 52 54
49 52 50 50 51
51 52 51 45 48
50 47 54 47 52
I wish to produce the following 3 x 4 output array.
196 194 199 207
204 205 196 194
200 204 197 192
In order to do this, you'll need four nested `for` loops.
The first two `for` loops will loop through the starting position of the subarray you want to sum. The second two `for` loops will loop through the subarray, summing the values.
To the original poster: If English is not your native language, write your question and expanation in your native language and use Google translate to translate your question and expanation into English. You need to clearly state the problem, possible inputs, and desired outputs for your question to make sense.