mercredi 1 juillet 2015

Creating a 2D array and finding max

I have to write a program that Creates a 2d array and asks the user for row and column size.

Create 2-D array say m :

ask the user to input row and column sizes from keyboard (use Scanner)

Assuming that the last digit of your ssn number is N, if the user input column size is bigger than N+5 ask the user to reinput the column size

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

pass the above array m and call the following two methods

findMaxCol(m)

returnAvg(m)

print out the avg of array m

In findMaxCol(double[][]array), find and print the largest sum of columns in the 2 d array

in returnAvg(double[][] array find the average of all elements in the array and return the average

I am having a hard time getting the random class to post double and finding the max column with average.

Scanner console=new Scanner(System.in);
    findMaxcoumn();
    returnAvg();

    double Random =new Random().nextDouble();
    int lastdigit=8;
    System.out.println("Write a 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 a column again");
        int k=console.nextInt();
        int [][] array2=new int[n][k];
        int [][] array2=rand.nextdouble(8.0)+4.0;
        }
        }
        }

       }




Aucun commentaire:

Enregistrer un commentaire