I am a beginner in Java. I want to get input from the user to a 2D array, and convert into a list of objects. When I hardcoded the data, it could be done as this way but, I want to get this object arrays from the user input. When I am going to do this way, it was giving
Tag: multidimensional-array
Validating elements of a 2D array
My code for making sure an element isn’t over 100 or less than 0 is: Except no matter what the input is the answer is always true My input array is test should = false if I input this no? College rules mean I cannot use break; or return anywhere other than the end of the sub module. Answer You
Printing a snake pattern using an array
I’m having trouble with an assignment where we are required to print out this array: My code is somewhat correct but it is not printing 10 and 19 where it should be. My output: My code: Can anyone detect what is causing the error? Any help would be appreciated. Answer This will generate the “snaking” pattern you described. It could
Converting a 1D array to a 2D array
Got an array: I need to convert it in two dimension: Below code: gives the result: How to get: Answer You’re assigning the wrong value to arr[i][j]:
How to calculate RECURSIVELY 2D array column in Java
I am stuck with a homework question for something fairly stupid. The mission is to find the smallest column sum on a 2D array and return it’s index. No loops allowed, only recursion. I managed the code, but I’m stuck with the simple task of calculating the column itself. This is the code I wrote so far: And this is
How can I check if a diagonal element in 2D array is occupied?
I’m trying to complete the nQueens puzzle problem with a 2D array. I’m having trouble checking to see if an element diagonal to the current element is occupied? I tried doing another for loop, but it …
Java – How to Solve this 2D Array Hour Glass?
I am working on a problem where I’ve to print the largest sum among all the hourglasses in the array. You can find the details about the problem here- What I tried: Input: Output: Expected Output: Screenshot: I don’t know where I’m doing wrong. I cannot understand why the expected output is 13. According to the description given in the
Why can’t i generate this 10×10 2D array?
I am trying to generate this 2D Array maze 10 by 10 with numbers 0-9 in each row for 10 rows, but I keep getting array out of bounds exception. I double checked my indexes and the loop format and everything looks standard. What is going on here? Why am I getting the out of bounds exception? Answer When you
Java array manipulation, invert an int[][] array
I am trying to flip each col in this array to invert the image. However, when I run my code, I get a mirror image of the second half of the image, for some ridiculous reason, that I cannot figure out. Can someone please tell me why this only works half-way? someArray is an int[][] array defined elsewhere in my
Checking to see if a 2d array is jagged
I am finishing up a program but having a bit of trouble with one last aspect. In this part of the program, I am testing to see if the array is jagged (same number of rows and columns). I want to use a nested for loop to do this but am having trouble with the logic and structure. For example,