Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

how do i: Write a program to input 2 numbers, first and diff. The program will then create a two-dimensional array of 4x4 in an arithmetic sequence which is printed out. For example, if first is 21 and diff = 5, the arithmetic sequence will be: 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96

OpenStudy (anonymous):

And then how do i reverse the diagonals? eg. 96 26 31 81 41 71 66 56 61 51 46 76 36 86 91 21

OpenStudy (anonymous):

in java

OpenStudy (anonymous):

Here's one way you could do it: for(int i = 0;i<4;i++) { for(int j = 0; j<4; j++) { if (i==j) { output[i][j] = first + (diff * ( ((3-i) * 4) + (3-j) ); } else { output[i][j] = first + (diff * ((i * 4) + j) ); } } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!