+ 3
Java array example
Can anyone answer this? I found this on a texbook but there's no example for the questions. All i know is the question letter a a. Declare an array alpha of 10 rows and 20 columns of type int. b. Initialize each element of the array alpha to 5. c.Store 1 in the first row and 2 in the remaining rows. d. Store 5 in the first column, and the value in each remaining column is twice the value of the previous column. e.Print the array alpha one row per line. f. Print the array alpha one column per line.
8 Antworten
+ 8
This question seems strange because all elements start off with the value 5.
Then, the 5s get replaced with 1s in the first row and 2s everywhere else.
The the 1s and 2s get overwritten by 5s in the first column, 10s in the second column, 20s in the third, and so on and so forth.
The first output would then appear as:
//20 columns worth for each row
5 10 20 40 80 ... [2^(20-1) * 5]
5 10 20 40 80 ... [2^(20-1) * 5]
...
5 10 20 40 80 ... [2^(20-1) * 5]
//continues until 10th row
The second output would transpose the columns as rows:
//10 columns worth for each row
5 5 5 5 5 ... 5
10 10 10 10 10 ... 10
20 20 20 20 20 ... 20
...
//continues until 20th column is listed as last row.
Based on my interpretation, steps b and c can be skipped. 🤷♂️
I'd like to hear from others if I'm missing anything.
+ 3
im sorry, i edited it now Ipang
+ 3
Clarrise✨ It sounds like this textbook question is poorly written as it suffers from ambiguity where a solution requires making assumptions.
Or perhaps it's intentionally trying to see if anyone is going to implement b and c or just skip them since the instructions from d essentially replace all values.
The bit that makes this vague for c and d is whether or not the specified values are added to:
- all positions within their respective row or col
- or any single position for the given row or col
If it's only for a single position per row or col, it doesn't specify which it should be.
One might assume the expectation is to store value X in the first element of each row or the first element of each column. Or one could assume to fill all positions with the same values per row or col
Either way, such assumptions on these kinds of questions are a sign of poor proofreading or perhaps some missing context yet to be revealed. 🤷♂️
+ 2
Add a language specifics in your thread tags please, 'help newbie' apparently doesn't give clarity on language context ☝
+ 2
All questions are connected to each other, So if I answer question A, I'll based my answer of Question B to Question A
+ 2
the questions are meant in a two dimensional array, too bad there's no sample output of the questions on the textbook, reason why i am looking for answers 😁
+ 1
I'll wait for your code then Clarrise✨
Actually, I also feel unsure of how this should be done, but if that really was how it says, then best try to make it following the instruction. Even nonsensical as it may be : )
0
Clarrise✨
Was each instruction (except for point a) meant to be done individually, or sequentially? I mean, are you supposed to do
A then B, A then C, A then D and so forth, or is it like
A then B then C ... F
I ask this because the instruction structure didn't look so clear, as David asked before (above).
P.S. I would appreciate it if you could post your code in attempt to solve this, so I can see where you need assistance or suggestion.
You can save your code in SoloLearn and share the saved code link by following this guide 👇
https://www.sololearn.com/post/75089/?ref=app