dividing matrix into four sub-blocksDoes a finally block always get executed in Java?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?What is the difference between a static and a non-static initialization code blockHow to reference sub-matrices within a matrixHow do I convert a String to an int in Java?Dealing with “Xerces hell” in Java/Maven?Find the largest-sum sub-matrixdivide matrix to blocks with parallel diagonal linesJava 8 Distinct by property
How can saying a song's name be a copyright violation?
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
Why is the sentence "Das ist eine Nase" correct?
Does int main() need a declaration on C++?
How could indestructible materials be used in power generation?
How badly should I try to prevent a user from XSSing themselves?
How do conventional missiles fly?
Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)
Why do I get negative height?
One verb to replace 'be a member of' a club
Is there a hemisphere-neutral way of specifying a season?
Send out email when Apex Queueable fails and test it
Venezuelan girlfriend wants to travel the USA to be with me. What is the process?
How to compactly explain secondary and tertiary characters without resorting to stereotypes?
Why were 5.25" floppy drives cheaper than 8"?
What historical events would have to change in order to make 19th century "steampunk" technology possible?
how do we prove that a sum of two periods is still a period?
Ambiguity in the definition of entropy
How to show a landlord what we have in savings?
Mathematica command that allows it to read my intentions
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
My ex-girlfriend uses my Apple ID to log in to her iPad. Do I have to give her my Apple ID password to reset it?
Can a virus destroy the BIOS of a modern computer?
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
dividing matrix into four sub-blocks
Does a finally block always get executed in Java?Fastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?What is the difference between a static and a non-static initialization code blockHow to reference sub-matrices within a matrixHow do I convert a String to an int in Java?Dealing with “Xerces hell” in Java/Maven?Find the largest-sum sub-matrixdivide matrix to blocks with parallel diagonal linesJava 8 Distinct by property
i want devide matrix into four sub-blocks equally by vertically and horizontallty in java (Here, we suppose that m and nare even numbers) .
for example we have matrix:
1 2 3 4 5 6
7 8 9 1 2 8
1 2 3 4 5 6
4 5 6 7 8 9
1 4 7 2 5 8
3 6 9 7 2 5
I want to display the last block that is:
7 8 9
2 5 8
7 2 5
how i can resolve this problem in java.
java
|
show 1 more comment
i want devide matrix into four sub-blocks equally by vertically and horizontallty in java (Here, we suppose that m and nare even numbers) .
for example we have matrix:
1 2 3 4 5 6
7 8 9 1 2 8
1 2 3 4 5 6
4 5 6 7 8 9
1 4 7 2 5 8
3 6 9 7 2 5
I want to display the last block that is:
7 8 9
2 5 8
7 2 5
how i can resolve this problem in java.
java
3
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
All you need is 4for
loops. Begin with the top left corner.
– Arnaud Denoyelle
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33
|
show 1 more comment
i want devide matrix into four sub-blocks equally by vertically and horizontallty in java (Here, we suppose that m and nare even numbers) .
for example we have matrix:
1 2 3 4 5 6
7 8 9 1 2 8
1 2 3 4 5 6
4 5 6 7 8 9
1 4 7 2 5 8
3 6 9 7 2 5
I want to display the last block that is:
7 8 9
2 5 8
7 2 5
how i can resolve this problem in java.
java
i want devide matrix into four sub-blocks equally by vertically and horizontallty in java (Here, we suppose that m and nare even numbers) .
for example we have matrix:
1 2 3 4 5 6
7 8 9 1 2 8
1 2 3 4 5 6
4 5 6 7 8 9
1 4 7 2 5 8
3 6 9 7 2 5
I want to display the last block that is:
7 8 9
2 5 8
7 2 5
how i can resolve this problem in java.
java
java
edited Mar 21 at 20:33
Sterling Archer
16.1k126191
16.1k126191
asked Mar 21 at 17:23
rouinrouin
13
13
3
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
All you need is 4for
loops. Begin with the top left corner.
– Arnaud Denoyelle
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33
|
show 1 more comment
3
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
All you need is 4for
loops. Begin with the top left corner.
– Arnaud Denoyelle
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33
3
3
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
All you need is 4
for
loops. Begin with the top left corner.– Arnaud Denoyelle
Mar 21 at 17:33
All you need is 4
for
loops. Begin with the top left corner.– Arnaud Denoyelle
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33
|
show 1 more comment
1 Answer
1
active
oldest
votes
Iterate over the lower-right part of the matrix. Here is an example for a square matrix. I am sure you will be able to make it more generic for non-square quadrants or to get other quadrants than the lower-right one.
public int[][] getQuadrantOfSquareMatrix(int[][] matrix)
int newDimension = matrix.length / 2;
int[][] toReturn = new int[newDimension][newDimension];
for (int i = 0; i < newDimension; i++)
for (int j = 0; j < newDimension; j++)
toReturn[i][j] = matrix[i + newDimension][j + newDimension];
return toReturn;
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285990%2fdividing-matrix-into-four-sub-blocks%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Iterate over the lower-right part of the matrix. Here is an example for a square matrix. I am sure you will be able to make it more generic for non-square quadrants or to get other quadrants than the lower-right one.
public int[][] getQuadrantOfSquareMatrix(int[][] matrix)
int newDimension = matrix.length / 2;
int[][] toReturn = new int[newDimension][newDimension];
for (int i = 0; i < newDimension; i++)
for (int j = 0; j < newDimension; j++)
toReturn[i][j] = matrix[i + newDimension][j + newDimension];
return toReturn;
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
add a comment |
Iterate over the lower-right part of the matrix. Here is an example for a square matrix. I am sure you will be able to make it more generic for non-square quadrants or to get other quadrants than the lower-right one.
public int[][] getQuadrantOfSquareMatrix(int[][] matrix)
int newDimension = matrix.length / 2;
int[][] toReturn = new int[newDimension][newDimension];
for (int i = 0; i < newDimension; i++)
for (int j = 0; j < newDimension; j++)
toReturn[i][j] = matrix[i + newDimension][j + newDimension];
return toReturn;
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
add a comment |
Iterate over the lower-right part of the matrix. Here is an example for a square matrix. I am sure you will be able to make it more generic for non-square quadrants or to get other quadrants than the lower-right one.
public int[][] getQuadrantOfSquareMatrix(int[][] matrix)
int newDimension = matrix.length / 2;
int[][] toReturn = new int[newDimension][newDimension];
for (int i = 0; i < newDimension; i++)
for (int j = 0; j < newDimension; j++)
toReturn[i][j] = matrix[i + newDimension][j + newDimension];
return toReturn;
Iterate over the lower-right part of the matrix. Here is an example for a square matrix. I am sure you will be able to make it more generic for non-square quadrants or to get other quadrants than the lower-right one.
public int[][] getQuadrantOfSquareMatrix(int[][] matrix)
int newDimension = matrix.length / 2;
int[][] toReturn = new int[newDimension][newDimension];
for (int i = 0; i < newDimension; i++)
for (int j = 0; j < newDimension; j++)
toReturn[i][j] = matrix[i + newDimension][j + newDimension];
return toReturn;
answered Mar 21 at 17:36
MWBMWB
8761819
8761819
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
add a comment |
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
You can’t assume that the matrix is square, only that both dimensions are even.
– Joakim Danielson
Mar 21 at 20:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285990%2fdividing-matrix-into-four-sub-blocks%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Iterate over the right part of the matrix. What did you try so far? Please show us your efforts
– MWB
Mar 21 at 17:28
how i can do this. can you help me?
– rouin
Mar 21 at 17:31
All you need is 4
for
loops. Begin with the top left corner.– Arnaud Denoyelle
Mar 21 at 17:33
I'm thinking a nested for loop where i and j start at n/2 or m/2. You should try to implement this yourself and come back with the problems you face and ask a more specific question.
– Patrick
Mar 21 at 17:33
Help us helping you by at least throwing in some code you did yourself. We will not code this for you.
– NaeiKinDus
Mar 21 at 17:33