-1

hello everyone I got this codes but I need to make some constraint on my arrays: public static void main (String[] args)

{Random myRand = new Random ();

// Pick array size T from 1 to 100.
int T = 1 + myRand.nextInt(5);
System.out.println("T="+(T));
int C = 1 + myRand.nextInt(100);
System.out.println("C="+(C));

// Declare array of size T.
int [] production_cost=new int [T];
int []stock1= new int [T];
int[]stock2= new int [T];
int[]fix_cost1= new int [T];
int[]fix_cost2= new int [T];
int[] Demands=new int[T];
// Fill the array with random numbers.
 {for (int i=0;  i< T; i++){
  production_cost[i] = myRand.nextInt(Integer.max(0,20));
   stock1[i] = myRand.nextInt(Integer.max(0, 20));
   stock2[i]= myRand.nextInt(Integer.max(0,20));

  fix_cost1[i]=myRand.nextInt(Integer.max(10, 20) );
  fix_cost2[i]=myRand.nextInt(Integer.max(20,30));
  Demands[i] = myRand.nextInt(Integer.max(1,C));}
    System.out.println("p2::"+Arrays.toString(production_cost));
    System.out.println("h1::"+Arrays.toString(stock1));
    System.out.println("h2::"+Arrays.toString(stock2));
    System.out.println("K1::"+Arrays.toString(fix_cost1));
    System.out.println("K2::"+Arrays.toString(fix_cost2));
    System.out.println("d::"+Arrays.toString(Demands));
Alex Filatov
  • 2,232
  • 3
  • 32
  • 39

1 Answers1

0

You can see this link : Fill an array with random numbers

You need to add logic to assign random values to double[] array using randomFill method.

Change

public static double[] list(){

anArray = new double[10]; 

return anArray;  } 

To

public static double[] list() {

anArray = new double[10];

    for(int i=0;i<anArray.length;i++)

    {

       anArray[i] = randomFill();

    }

   return anArray; }

Then you can call methods, including list() and print() in main method to generate random double values and print the double[] array in console.

  public static void main(String args[]) {

    list(); print();  }

One result is as follows:

-2.89783865E8

1.605018025E9

-1.55668528E9

-1.589135498E9

-6.33159518E8

-1.038278095E9

-4.2632203E8

1.310182951E9

1.350639892E9

6.7543543E7

Community
  • 1
  • 1
UtopiaIsGood
  • 169
  • 3
  • 15