java - Creating a 2D array and finding max -


i have write program creates 2d array , asks user row , column size.

create 2-d array m :

ask user input row , column sizes keyboard (use scanner)

assuming last digit of ssn number n, if user input column size bigger n+5 ask user reinput column size

fill arrays elements double numbers in range of (4.0 , 11.0) using of random object

pass above array m , call following 2 methods

findmaxcol(m)

returnavg(m)

print out avg of array m

in findmaxcol(double[][]array), find , print largest sum of columns in 2 d array

in returnavg(double[][] array find average of elements in array , return average

i having hard time getting random class post double , finding max column average.

scanner console=new scanner(system.in);     findmaxcoumn();     returnavg();      double random =new random().nextdouble();     int lastdigit=8;     system.out.println("write row");     int n=console.nextint();     system.out.println("write column");     int y=console.nextint();        int [][] array=new int[n][y];       if(y>lastdigit+5){         system.out.println("write column again");         int k=console.nextint();         int [][] array2=new int[n][k];         int [][] array2=rand.nextdouble(8.0)+4.0;         }         }         }         } 

it looks might need more reading on how arrays work. create array line:

int [][] array2=new int[n][k]; 

this should work fine, next line is:

int [][] array2=rand.nextdouble(8.0)+4.0; 

this 1 doesn't know of. need use 2 loops, 1 first dimension of array. other inner loop second dimension. instance:

for(int = 0; < n; i++) {   for(int j = 0; j < k; k++) {     array2[i][k] = rand.nextdouble(8.0) + 4.0;   } } 

try reading the documentation oracle.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -