I'm trying to understand this question
Norm Radder wrote:
I'm trying to understand this question
The description of the program seems clear to me. What problem(s) are you having with it?
Given this two dim array show what the expected result is: {{1,2}, {3,4}}
Adebiyi Itunuayo wrote:Thanks for your response, I'm confused on how to write the logic for the "Modify the..." down.
I know that to begin this, I must define my rows and columns
int [][] rows = new int [5][4];
I just don't know how to proceed from here.
Norm Radder wrote:
I'm trying to understand this question
The description of the program seems clear to me. What problem(s) are you having with it?
Given this two dim array show what the expected result is: {{1,2}, {3,4}}
Norm Radder wrote:First can you post an example of a two dim array
and then do the process on it manually as described in the question
and post the resulting array
to show that you understand what the program is supposed to do.
Once we agree on what the result should be, then we can work on designing the code to do it.
Here is a 2d array which prints :
246
135
int combination[][] = { {2,4,6}, {1,3,5} };
Norm Radder wrote:
Here is a 2d array which prints :
246
135
int combination[][] = { {2,4,6}, {1,3,5} };
Given that array, can you manually create the array for the solution?
We'll work on the design and coding when we agree on what the program is supposed to do.
Some corrections for your code to use the array's length attribute:
This code should work with different sizes for the array.
what it means to "modify the last element
Norm Radder wrote:
what it means to "modify the last element
If this is the array: 1,2,3 then 3 is the last element.
I assume what is meant by modifying an array element is to assign it a value:
or a 2d array would it be:
combination[0][2] and combination[1][2]
Norm Radder wrote:Can you post the contents of the array for the desired solution so we agree on what the solution is?
or a 2d array would it be:
combination[0][2] and combination[1][2]
That only works for an array with two rows that are 3 elements long. You need a solution that works for arrays of different sizes.
You can use the array's .length attribute to get to the last element. Since the index of the last element is the array's length - 1,
Norm Radder wrote:
That would be the index of the last row in the rows two dim array. I don't know what that would be used for.
There should not be a 0 used as an index here. The code should use the variable that is the index for that row. The code uses i to index the rows in the array and j to index the columns in a row.
Norm Radder wrote:The code will work on a row at a time so there will only be one variable that will have the location of the last element in the current row being worked on.
You can not easily have a variable for each row because the number of rows may not be known.
The code should be written so it works with arrays of different sizes.
Please wrap your code in code tags: Select the code and press the Code button.
Given this array:
What will be the final contents of that array after the program runs?
Adebiyi Itunuayo wrote:I'm trying to understand this question, can you explain it in pseudo code or better please: Create a two dimensional array of integers called rows[][] with five rows and four Columns. Modify the array so that the last element in each row is equal to the sum of all the elements in the row minus the last element. Initialize rows[][] with data any way you choose and print out the modified array.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:Adebiyi,
this: "last element in each row is equal to the sum of all the elements in the row minus the last element".
seems to me to be a confusing way of saying: sum the elements of each row to k-1 and put the result in element k.
Les
Adebiyi Itunuayo wrote:I'm trying to understand this question, can you explain it in pseudo code or better please: Create a two dimensional array of integers called rows[][] with five rows and four Columns. Modify the array so that the last element in each row is equal to the sum of all the elements in the row minus the last element. Initialize rows[][] with data any way you choose and print out the modified array.
There are three kinds of actuaries: those who can count, and those who can't.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|