Range in Array Java -


i need complete task. not entirely sure how range array. think supposed use loop somehow not work.

this have far:

import java.util.*; public class a2_1  {     static scanner x = new scanner(system.in);     public static void main(string[] args)       {         int [] myarray = new int [1000000];              int x;      ( x = 0; x <= 100; x++)     {           myarray [x] = x+1;     }     system.out.println(myarray);     } } 

this task:

"create program generates 1,000,000 integer random values in range of [1,..,100] , given x (between 1 , 100) taken user input computes "(๐‘‡๐‘œ๐‘ก๐‘Ž๐‘™ ๐‘›๐‘ข๐‘š๐‘๐‘’๐‘Ÿ ๐‘œ๐‘“ ๐‘’๐‘™๐‘’๐‘š๐‘’๐‘›๐‘ก๐‘  ๐‘™๐‘’๐‘ ๐‘  ๐‘กโ„Ž๐‘Ž๐‘› ๐‘œ๐‘Ÿ ๐‘’๐‘ž๐‘ข๐‘Ž๐‘™ ๐‘ก๐‘œ ๐‘ฅ)/1,000,000". value must comparable cdf of uniform distribution u[1,100] @ point x."

im not going give answer since sounds homework break down manageable chunks.

first, generate 1000000 random numbers between 1 , 100. on right track , combine dawnkeepers hint. int[] randoms = new int[1000000]; int array size of 1000000. iterate on each index , assign random number(see above). have array million random numbers. generating million randoms can lengthy procedure depending on machine, yea.

next, use scanner class users input.(pro tip: dont use same variable name scanner variable in loop lol). if check make sure enter number between 1 , 100. if(val > 0 && val <= 100). if passes, move on, else quit or prompt user give new input. using scanner pretty trivial wont go this.

finally, iterate through list of randoms , keep counter of how many numbers less or equal x.

int counter = 0; for(int = 0; < randoms.length; i++) {   //if randoms[i] less or equal x, counter++ } 

take counter , math, int final_answer = counter/randoms.length;

that's it. there more efficient ways of doing tried make simple follow. if misread question, sorry.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -