Hi,
I know how to code prompts for user input in a general sense with the scanner object, but am not sure how to input data for multi-dimensional arrays.
I don't know if the data can be input all at once for all columns/rows, or if the data has to be input from the users separately for the rows, then for the columns.
I have numbers stated directly so far, but now want to have users input their own numbers for use in the program.
import java.util.Scanner;
public class Students1
{
static int [][]coffeeArray2 = { {1,2}, {2,3}, {3,4}, {4,5}, {5,6} };
static Scanner myInput = new Scanner( System.in );
public static void main (
String [] args)
{
System.out.println( "Display my bins:" );
displayArray( coffeeArray2 );
System.out.println( "The Total lbs in bins is:" + calcTotalCoffee( coffeeArray2 ));
}
public static void displayArray( int coffeeArray2[][] )
{
for( int i = 0; i< coffeeArray2.length; i ++)
{
for(int j = 0; j< coffeeArray2[i].length; j ++)
System.out.printf( "%d ", coffeeArray2[i][j] );
System.out.println();
}
}
public static int calcTotalCoffee( int coffeeArray2[][] )
{
int total = 0;
for (int i = 0; i < coffeeArray2.length; i++)
{
for (int j = 0; j < coffeeArray2[i].length; j++)
total = total + coffeeArray2[i][j];
}
return total;
}
}
Thanks,
Anise