java - How do i input all the values from one array into random indexes of another array? -
java - How do i input all the values from one array into random indexes of another array? -
i cant figure out how input money amounts,which stored in array (case_value), other array, (cases).i trying randomly. programme run never finishes. have far. in case couldn't guess, trying re-create format of deal or no deal. also, if there way create code more efficient, appreciate it. give thanks help.
import java.util.scanner; import java.lang.math; public class dond { public static void main (string [] args) { scanner sc = new scanner (system.in); int [] cases=new int [26]; //array cases int [] case_value=new int [26]; //array money amounts int b=0; case_value[0]=1; // money amounts case_value[1]=2; case_value[2]=5; case_value[3]=10; case_value[4]=25; case_value[5]=50; case_value[6]=75; case_value[7]=100; case_value[8]=200; case_value[9]=300; case_value[10]=400; case_value[11]=500; case_value[12]=750; case_value[13]=1000; case_value[14]=5000; case_value[15]=10000; case_value[16]=25000; case_value[17]=50000; case_value[18]=75000; case_value[19]=100000; case_value[20]=200000; case_value[21]=300000; case_value[22]=400000; case_value[23]=500000; case_value[24]=750000; case_value[25]=1000000; (int i=0;i<26;i++) //distributing money { while (cases[b]==0); //checks if case filled { int r=(int)(math.random()*26); //randomizes money amounts in case if (cases[r]==0) { b=r; cases[r]=case_value[i]; //inserts money amount in case } } } (int i=0;i<26;i++) //outputs value in cases { system.out.println(cases[i]); } } }
if want input shuffled, why not utilize built in collection.shuffle method?
// fill array input final list<integer> list = new arraylist<>(array.length); (int = 0; < array.length; i++) { list.add(array[i]); } collections.shuffle(list); // work shuffled list
java arrays
Comments
Post a Comment