java - 2D array with user input -
i want create 5 row 2 column int array , have user input each value in array. want use stdin input. why won't work? please help! thanks.
this effort:
int [][] = new int [5][2]; int i; int j; for( = 0; < 4; i++ ); { for( j = 0; j < 2; j++ ); { system.out.println( "month number (e.g. august = 8)" ); int month = stdin.readint(); a[i][0] = month; system.out.println( "year number (e.g. 2007)" ); int year = stdin.readint(); a[i][1] = year; } }
you're asking both values user, no need nested loop:
int [][] = new int [5][2]; for(int = 0; < 5; i++ ) { system.out.println( "month number (e.g. august = 8)" ); int month = stdin.readint(); a[i][0] = month; system.out.println( "year number (e.g. 2007)" ); int year = stdin.readint(); a[i][1] = year; }
i've removed semicolon ;
had after first loop making useless, , fixed iteration 4 ( you're looping [0..4) , want [0..5) ).
j
removed since nested loop not needed , i've make i
local loop.
Comments
Post a Comment