I have an array that will have two columns and a variable number of rows(based on user input). I am attempting to store user input so that I can later print out the pairs of data that they entered (time, money), I take this inputs at the same time and would like to be able to loop through the array so that I can print them out as they were entered. Right now what im doing isn't working.
I don't know if it's the way I am storing them or the way I am trying to print them. Make sure to read in line comments, as this is not how my code is actually set up, I am trying to make it easier to program and debug.
I am having a bit of a difficult time. Here is my attempt:
I don't know if it's the way I am storing them or the way I am trying to print them. Make sure to read in line comments, as this is not how my code is actually set up, I am trying to make it easier to program and debug.
I am having a bit of a difficult time. Here is my attempt:
public static void main(String args[]) { float [][] values = new float[2][10]; // i have it as 10 rows right now, but i need to make it a variable int rows = 0; float time = 3; // these are typically user input float money = 6; // these are typically user input // this code is usually in a gui, whenever a button is pressed, this is how i store the data to an array, i maintain the row variable locally values[rows][1] = time; values[rows++][0] = money; int row; int col = 0; // loop through print a row that shows what the user entered for time and money for(row = 0; row < 10; row++) for(col = 0; col < values[row].length; col++) System.out.println("Minutes= " + values[col][row] + " Earnings= $" + values[col][row] + "\n"); }