All Questions
Tagged with java multidimensional-array
4,291 questions
2
votes
1
answer
77
views
Rotation of square Matrix not working correctly after first rotation
Please check the below code, the mat array after the second rotation should be identical to the target array tar. However, it is not happening. Could you please review to check where the logic is ...
2
votes
3
answers
152
views
Why do Java 2D arrays allow holding rows larger than their specified size?
While coding, I noticed an interesting outcome. I created a 2D char array with a declared size of char[10][10]. However, I found that I could assign char arrays with more characters than the specified ...
0
votes
5
answers
152
views
Stream through a portion of a 2D array in Java
Let's say you have a matrix
[[1,2,5],[3,4,6]] and you need to work with the first two elements of each row together [1,2,3,4]. You don't want to store this in memory or use nested loops. Is there a ...
-3
votes
1
answer
55
views
My 2D ArrayList syntax is not working in Netbeans
I am following BroCode's Java Full Course on YouTube and encountered this error. NetBeans IDE does not allow the syntax ArrayList<ArrayList<String>> groceryList = new ArrayList<String&...
1
vote
1
answer
71
views
Detect diagonal in matrix in Java (victory in Connect Four game)
I'm making a Connect 4 game. The objective is to align four items the same way.
I have a double array : Player[6][7] which is filled by the player that played on that slot.
I'm working on victory ...
0
votes
3
answers
167
views
Is there a reason why my code skips lines?
so i have this java code:
String line;
int numrow=5, numcol=5;
BufferedReader reader;
String arr[][]=new String [numrow][numcol];
try{
reader=new BufferedReader (new FileReader(pname));
int ...
-4
votes
1
answer
70
views
Why is my code giving wrong answer when using 2d ArrayList and passing when using 2d arrays?
Here is the DP question,
Given a �?N’ * ’M’ maze with obstacles, count and return the number of unique paths to reach the right-bottom cell from the top-left cell. A cell in the given maze has a value '...
0
votes
2
answers
48
views
how to make a row in a matrix only go as long as the first number?
so i have this exercise on matrixes which needs to be done with two dimensional arrays. the first part was that you have n, which goes from 1 to 9. for each row, you need to output the muliplication ...
1
vote
2
answers
471
views
Problem with counting Battleship sunken ships/ships (Java)
So I am making a method for a battleship game which consists of ships ranging from 2-5 squares horizontally on a 10x10 grid in Java. This method is to count the number of sunken ships on the grid ...
0
votes
1
answer
53
views
Java - Why can't i take an array of a superclass, and get the subclass functions?
I'm trying to write a Chess Program from scratch. I have a superclass called "Piece", and subclasses for all the individual chess pieces (Pawn, Bishop, Knight, ect). I also have another ...
0
votes
1
answer
34
views
How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
I basically have to create a method that takes in a string array and a 2D array consisting of three double arrays and puts the first string with the first array, second string with the second array, ...
1
vote
1
answer
25
views
Java Matrix Search using binary search, wrong working of for loop
public class MatrixSearch {
public static void main(String[] args) {
int[][] mat = {
{10, 20, 30, 40},
{15, 25, 35, 45},
{27, 29, 37, 48},
...
0
votes
0
answers
83
views
Coding battleship in java using Jbuttons in a Jframe
I'm trying to code battleship in a JFrame with 2 matrices of 2d arrays with JButtons. I have most of the code ready to go, but I'm running into a problem with placing the ships. The problem is that ...
-1
votes
1
answer
51
views
How to get specific values from rows in multidimensional arrays using 2 column as filter [closed]
I have an array like this
String[][] array = {{"A", "1"},
{"B", "1"},
{"C", "2"},
...
-1
votes
1
answer
74
views
How do I put in individual values into an 2-dimensional array with an unknown length?
I am trying to write a code that will allow the user to input values for an arrays row and columns. I have finished that part, but now I am tasked with the problem of inputting a value for index 00, ...