1
vote
2answers
34 views

Printing out a specific number of digits based on the number with longest length?

I'm looking to print out a number matrix using parallel arrays. I want to find a way to ensure that each number is printed out with a proper amount of digits, based on how long the longest digit ...
-1
votes
1answer
29 views

I am confused on copying 2D arrays

I was reading this post on Stack overflow: copy a 2d array in java and I am a little confused on how the clone method works here... public int[][] CopyMap(int[][] Map) { int [][] copy = new ...
1
vote
2answers
28 views

Filling in the main diagonals in a 2D array

I am trying to write a code that fills in the 2 main diagonals in an NxN matrix, for example: if N=5 (which is entered through command line), we would have a 5x5 matrix filled with zeros and the ...
-1
votes
0answers
15 views

How do I store a 1D char array into a specific position in a 2D array in java?

I'm trying to take a 1D character array and store it in each position in a 2D array. Here's what I've got, trying to store the array {'a','b','c'} into each position of my 2D array. char[][] ...
0
votes
3answers
22 views

Various 'players' on a 2D Grid, how should players reference the grid?

Say I have created a class called Grid which is a 2D array and has the function boolean canMove(Position fromPos, Position toPos) { // Determines whether a we can move from fromPos to toPos } ...
0
votes
2answers
23 views

Why does this code for shifting left in a 2D array not work and shifts left 2 instead?

This code is to shift a 2D array "arr" to the left completely once it runs through, but for some reason, the elements are shifting over by two. public static void shiftLeft() { ...
-6
votes
0answers
54 views

filling and printing a 2d array from 100 to 1 [duplicate]

I'm new to java and was wondering how I can go about filling and printing a 2d array [10][10] from 100 down to 1, like a snakes and ladders board. Thanks for any help!
0
votes
4answers
44 views

Matrix operations in Java

I looked for this everywhere, but I am wrong somewhere. In my Java program, I created few 2D Arrays. Now, I need to form new 2D arrays with previous, like, inverse, transpose, multiplying , LEFT ...
0
votes
0answers
44 views

Arrays containing indexes to retrieve values from another array

I have this problem and I don't know if it is possible to implement.. but here it goes. Basically, I have to get the position of the conjunctive query variables and apply those indexes to retrieve ...
0
votes
3answers
60 views

Java Comparing Two Dimensional Arrays

I really need help in comparing two dimensional arrays. In case I have the following values of arrays: dok1[paragraf][kalimat] dok2[paragraf][kalimat] *dok1 [0][0] = Deskripsi Hotel [1][0] = ...
0
votes
0answers
13 views

How can I compare content of a 2d array of JButtons to another 2D array?

first post! There are lots of posts on comparing 2d-arrays, and about JButtons, but I can't find a solution to my problem. Sorry if I've duplicated! I have a binary puzzle game, the "board" of which ...
0
votes
3answers
40 views

Save part of an 2D array into another 2D array Java

I have a 2D array which holds an ASCII map. I have another function called botLook() which needs to store a section of the map into another 2D array. This is a section of the map which the bot can ...
0
votes
2answers
30 views

2 Dimentional array with Hash-map

Is there a way to put a 2d array into a Hash map setup? Example of the array would be two strings {"John", "red"}, {"George", "blue} And I would want red to ...
1
vote
4answers
58 views

Check duplicate in rows and columns 2D Array

how would I go about checking a duplicate for columns and rows and return true or false depending if there's duplicates. For example 1 2 3 3 1 2 2 3 1 Would return true because no duplicates, ...
0
votes
2answers
52 views

Reverse the rows of a 2d array

Yesterday I asked a very similar question and I kind of messed up with asking it. I need to pass an array to a method and inside of that method I need to swap the rows around so if it's 1 2 3 3 2 ...
0
votes
2answers
30 views

How to display numbers on the left side and on the bottom of my 2D array?

I need to print a 2 dimensions array with some numbers on the left side and on the bottom. Here is my code for the initialization, wich is in the class Grille : class Grille { String[][] grille = ...
3
votes
2answers
42 views

how do you add to a 2D arraylist

I have the following code. I know the star is correct but I can't add to the arraylist private ArrayList<int[]> action = new ArrayList<int[]>(); action.add(new int[2]); then I have ...
-1
votes
1answer
39 views

2D Array in Java with number manipulation

My goal is to Create a 5x5 array and fill it with random integers in the range of 1 to 25. Print this original array Process the array, counting the number of odds, evens, and summing all of the ...
0
votes
3answers
56 views

Print out 2D array radios in Java

I am creating a Java Dungeon game and so far it imports a ASCII map into a 2d array. A player is then added and can roam around the dungeon using CLI. The player has to pick up all the gold before he ...
0
votes
2answers
34 views

Create and sort 2d array from file

Okay so basically I have to accomplish 2 things with this code. 1. Sort the two columns from the file into an array and 2. arrange them in order from largest to smallest based on the second column. ...
-3
votes
3answers
49 views

ArrayIndexOutOfBoundsException, only prints first line

I am making a dungeon game in Java. I have created a method that stores a map in a 2D array. The array looks like this: [[#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #], [#, ., ., ., ., ., ...
0
votes
2answers
110 views

Simple Java 2d array maze

Hello Stackoverflow people I am working or understanding how to create a simple java 2d maze that should look like this: int [][] maze = { {1,1,1,1,1,1,1,1,1,1,1,1,1}, ...
0
votes
4answers
40 views

Infinite Loop in Java 2d array program

The program is supposed to end and give the amount of correct answers once the last question is answered. Instead the program goes back to the initial question in the loop. "What is the capital of ...
0
votes
1answer
17 views

Moving the rows in my grid

I'm having trouble trying to move the rows to the left. The grid is from my input.txt file that I created.I created the method RL which is supposed to move the rows to the left. This is what I ...
0
votes
1answer
32 views

NoSuchElementException 2-d array

I keep getting NoSuchElementException but I'm not sure why. I know the error is for the scanner but don't know the reason this error is happening. I included the input file. import java.util.*; ...
0
votes
2answers
62 views

issue with for loops in 2D array program

Okay so my current assignment has me making a program that can mimic percolation, meaning that it has to read an array, where 1 means the space is closed, 0 means the space is open. Next, it must ...
0
votes
2answers
65 views

Import ascii world map in Java

I need to import a as ascii map into my Java game to set the world you will be able to move around in. For example. ################### #.................# #......G........E.# #.................# ...
0
votes
1answer
65 views

Find a location of a value on a 2d array in java

I have input values for my 2d array, which is 5 by 2 in size. I have occurences of each number on one column. and each number on the other column I have found the max value of occurrences, and need ...
0
votes
4answers
93 views

Index out of bounds when using a two-dimensional array

I am creating a text based minesweeper game in Java. The game works fine if a user creates a perfect square for a game board, however if they enter two different values, I get an exception at the ...
0
votes
0answers
52 views

how to pass 2d array to constructor

I am trying to populate a 2D array in java and need help to make an array appear in a JFrame window for a Game of Life project. I've been given a class that includes a constructor called LifeWindow, ...
0
votes
1answer
58 views

java tic tac toe user chooses board size and how many in a row to win (no GUI)

im making a tic tac toe game where the user can choose the the board size and how many in a row needed to win. for example a user can make the board 8*8 and say that you need 6 in a row to win. ...
-1
votes
2answers
42 views

declaring a 2d array method

I am writing a Game of Life java code for a school project and need to declare a method that calls a constructor from a separate class. I am not sure if I'm writing this correctly, specifically the ...
0
votes
2answers
26 views

Creating and initialising a 2D Array in Java

I haven't used 2D Arrays before so apologies for any 'obvious statements'. I want to create a 2D Array for a 15 by 20 'table' and want the following to be applied: I want each row to be a separate ...
0
votes
4answers
26 views

Out of bounds searching 2 dimensional array

I'm trying to search through an array of arrays (17 rows and 26 columns) for one integer and print the index of that integer. For the sake of easy testing I've set the integer I'm searching for to 0, ...
0
votes
2answers
24 views

How to input a string one charecter at a time into a 2d array

So i have a string and i need to put it into a 2d array this is what i have so far. mazeString = ".............." char[][] mazeArray = new char [50][30]; for (int i = 0; i < ...
0
votes
1answer
28 views

Place String into 2 dimensional array

To put a String into a single array is easy but I want to put a string into a 2d char[][]; I'm stuck here, can some one help me please ... Thank u, ans sorry for my bad English! String woord = ...
0
votes
3answers
55 views

Java cannot create simple 2d boolean array

Running the code: public static boolean[][] makeright(boolean tf, BufferedImage in){ boolean[][] ret = new boolean[in.getWidth()][in.getHeight()]; Arrays.fill(ret, tf); ...
1
vote
4answers
39 views

Importing a file to a 2d array in java

I am trying to import items from a file and put it in 3 different arrays and I am getting some errors. Here is the code I have so far: package project1; import java.io.File; import ...
0
votes
2answers
37 views

Java - Two dimensional system for a board

I am making a board for the game sokoban with Java. I wonder what would be the best implementation? Arrays? ArrayLists? Lists? The pieces would be represented as a string at this time, but might ...
0
votes
2answers
16 views

I'm trying to use the specific key ' in my binary converter program, but it creates a syntax error

Here's a part of the working code. I give you a few examples of the working comparisons, but the comparison with the apostrophe (') key just doesn't work. Any ideas on how to fix this? ...
0
votes
3answers
31 views

importing data from a large file into a 2d Array

I am trying to import a large data file and insert the information into a 2D array. The file has around 19,000 lines, and consists of 5 columns. My code is absolutely correct, there are no run time ...
0
votes
2answers
43 views

import large data into a 2d array

I get an exception when I run this program, its big file filled with data, I am trying to import the data from that file and insert the information into a 2d array, though, the file consists of around ...
0
votes
1answer
84 views

Stuck in using 2D arrays?

I am not good with arrays.In the below code there are 2 methods which takes the data from two 2D Arrays.The first method COMBINATION is working correctly.But the second Method doesn't. Am I doing ...
0
votes
1answer
37 views

getting rows and columns count of a 2D array without iterating on it

I have a function which takes 2D array. I am wondering if there is anyway to get rows and columns of the 2D array without having to iterate on it. Method signature is not to be changes. Function is ...
0
votes
3answers
88 views

Displaying 2D array contents on GUI colours

I'm in the process of creating a agent bases modelling program. So far I have the relavent classes to model a simulator, grid, different agents etc. I've also created a 2D array of object e.g. agents ...
1
vote
4answers
31 views

How to fix 2D Array that prints as one column

so this is what my code actually looks like, i was trying to make a simple 2d 10 by 10 array with just zeros at first. The zeros print in one column with breaks where a new column should be starting ...
-1
votes
2answers
92 views

Beginner 2D-Array out of bounds exception

I'm having some difficulties trying to figure out how to implement a second array to calculate the averages of my marks program. I'm using 1 2D array to store the scores each student received on each ...
0
votes
1answer
66 views

Determine ASCII value of a row/column in a 2D array of characters

Trying to figure out how to go about calculating the total value of ASCII characters in a row of a 2D array. From what I understand I must create a for-loop to loop through each instance within the ...
1
vote
4answers
54 views

Java for loops and 2D arrays

This code should be so simple, yet isn't working at all. It doesn't do anything. To my understanding it should print out a 10 by 10 grid of random numbers below 21. import java.util.Random; public ...
0
votes
2answers
46 views

Multiplying an 2d an ArrayList with a vector

I am trying to make multiplication of a mXn matrix and a mX1 vector in java. To do so, I am using a 2d arraylist for matrix and an ArrayList for the vector. My code is the following: ...

15 30 50 per page