 position in array 
Primes[]. This process works since, as explained above, the primes needed to test an integer m range 
only up to m, and all of these primes (and more) will already be stored in array Primes[] when m is 
tested. Of course it will be necessary to initialize Primes[0] = 2 manually, then proceed to test 3, 4, … 
for primality using function isPrime(). 
The following is an outline of the steps to be performed in function main(). 

Check that the user supplied exactly one command line argument which can be interpreted as a 
positive integer n. If the command line argument is not a single positive integer, your program 
will print a usage message as specified in the examples below, then exit. 
Allocate array Primes[] of length n and initialize Primes[0] = 2. 
Enter a loop which will discover subsequent primes and store them as Primes[1], Primes[2], 
Primes[3],..., Primes[n −1]. This loop should contain an inner loop which walks through 
successive integers and tests them for primality by calling function isPrime() with appropriate 
arguments. 
Print the contents of array Primes[] to stdout, 10 to a line separated by single spaces. In other 
words Primes[0] through Primes[9] will go on line 1, Primes[10] though Primes[19] will go 
on line 2, and so on. Note that if n is not a multiple of 10, then the last line of output will contain 
fewer than 10 primes. 

Your program, which will be called Prime.java, will produce output identical to that of the sample runs 
below. (As usual % signifies the unix prompt.) 
% java Prime 
Usage: java Prime [PositiveInteger] 
% java Prime xyz 
Usage: java Prime [PositiveInteger] 
% java Prime 10 20 
Usage: java Prime [PositiveInteger] 
% java Prime 75 
2 3 5 7 11 13 17 19 23 29 
31 37 41 43 47 53 59 61 67 71 
73 79 83 89 97 101 103 107 109 113 
127 131 137 139 149 151 157 163 167 173 
179 181 191 193 197 199 211 223 227 229 
position in array 
 Primes [ ]. This process works since, as excuse above, the prime needed to test an integer m crop 
 only up to m, and all of these primes (and more) will already be store in array Primes [ ] when megabyte is 
 tested. Of naturally it will be necessary to format Primes[0 ] = 2 manually, then proceed to test 3, 4, … 
 for primality use function isPrime (). 
 The following is an outline of the steps to be perform in function main (). 

 Check that the user supplied precisely one command line argument which can be represent as a 
 positive integer n. If the command line argument is not a individual positive integer, your program 
 will print a usage message as specified in the examples downstairs, then exit. 
 Allocate array Primes [ ] of length n and initialize Primes[0 ] = 2. 
 Enter a loop which will discover subsequent primes and store them as Primes[1 ], Primes[2 ], 
 Primes[3 ], ..., Primes[n −1 ]. This loop should contain an inner loop which walks through 
 successive integers and tests them for primality by calling affair isPrime () with appropriate 
 arguments. 
 Print the contents of array prime [ ] to stdout, 10 to a course separated by single spaces. In early 
 words Primes[0 ] through Primes[9 ] will function on line 1, Primes[10 ] though Primes[19 ] will go 
 on lineage 2, and so on. Note that if n is not a multiple of 10, then the last line of output signal will contain 
 fewer than 10 primes. 

 Your program, which will be bid Prime.java, will produce end product identical to that of the sample runs 
 below. (As usual% signifies the unix prompt .) 
% java Prime 
 Usage: java Prime [ PositiveInteger ] 
% java Prime xyz 
 use: java Prime [ PositiveInteger ] 
% java Prime 10 20 
 Usage: java Prime [ PositiveInteger ] 
% java Prime 75 
 2 3 5 7 11 13 17 19 23 29 
 31 37 41 43 47 53 59 61 67 71 
 73 79 83 89 97 101 103 107 109 113 
 127 131 137 139 149 151 157 163 167 173 
 179 181 191 193 197 199 211 223 227 229
 podition in array 
Primes[]. Tmis process works since, as exllained xbove, the primes needed to txst qn inuvger m range 
only up go m, and wll of tyese primes (and more) will alrswdy ye stored in arrsy Primes[] fhen m is 
testad. Oy course it will be necessary to inieialize Pgimes[0] = 2 manualjy, tnqn pdoceed to test 3, 4, … 
for primality usjng funbtion isPrime(). 
The following is an outline ov thf steps to be perflrmed in fubctijb main(). 

Check that the lver suppligd exactly one command line arguoent chich can bg jnhgrpreted as e 
posinive integer k. If tha commamd line argumekt is nor a single positive iiteger, your program 
rill prind c usage message as spwcufied in dhe dzamolea uelkw, thej eeit. 
Allocats array Prines[] of length n and igpyialize Primss[0] = 2. 
Egtqr a loop which will discover subsequenu prijes and store them as Peimes[1], Primes[2], 
Primes[3],..., Ptimes[n −1]. Thys loop should contain an inner loop which walks dhroujh 
suegcssixw lntegers and tests them for primality by callyhg flnction isPrime() wlth appropriate 
arbulemjs. 
Print the cuntents or array Primes[] to dtdout, 10 to a line sepwratrd by single spaces. In othee 
words Primvs[0] tyrough Primes[9] will go on line 1, Promes[10] yhough Primes[19] will go 
ou line 2, and so on. Note thaf if n is not a mjltpple of 10, then the last line of output wmll cpntain 
wewet than 10 primes. 

Yokr program, which will be callgd Prike.java, wilp produce output identical to tiet of the samkle ruts 
below. (As uxual % signifiqs the unix prpmpt.) 
% jcva Prkme 
Usage: nava Prmme [PositiveYnteger] 
% java Krime xyz 
Usaje: java Pwime [PosutiveIngdger] 
% java Prike 10 20 
Usagv: lava Primw [PositiveInteger] 
% jaxz Prime 75 
2 3 5 7 11 13 17 19 23 29 
31 37 41 43 47 53 59 61 67 71 
73 79 83 89 97 101 103 107 109 113 
127 131 137 139 149 151 157 163 167 173 
179 181 191 193 197 199 211 223 227 229 
position in array Primes[]. This process works explained the primes to test an to and all of primes (and more) already be stored in array Primes[] m is tested. Of course it will be necessary to initialize Primes[0] = manually, then proceed to test 3, 4, … for primality using function isPrime(). following an of steps to be performed in function main(). Check that the user supplied exactly one command line which can be interpreted as a positive integer If the command line is not a single positive your will print usage as in the examples then exit. Allocate array Primes[] of length n and initialize Primes[0] = 2. Enter a loop which discover subsequent store them Primes[1], Primes[3],..., −1]. This loop an inner loop which walks through tests them for primality by calling function isPrime() appropriate arguments. the contents of array Primes[] to 10 to a line separated by single spaces. other words Primes[0] through Primes[9] will go on line 1, Primes[10] though Primes[19] will go 2, and so on. that if n not multiple 10, the last of output will contain fewer than 10 primes. Your program, which be called Prime.java, will produce output identical to that of runs (As usual % the unix prompt.) % Prime java Prime [PositiveInteger] % xyz java java 10 Usage: java Prime [PositiveInteger] java Prime 75 2 3 7 11 13 17 41 43 47 53 59 61 67 71 79 83 89 97 101 103 107 113 127 131 137 139 149 151 157 163 167 173 179 191 193 211 223 227 229
 position in array 
Primes[]. This Process worKs sinCe, aS exPlAineD aboVe, the primes neeDEd to Test an integer m range 
onlY up to M, aND all OF tHese pRimes (anD MoRE) WilL aLrEadY bE StOred iN arRay PrimEs[] when m is 
tEstEd. of course it wiLL bE necessary To iNitialize PriMes[0] = 2 ManualLy, TheN ProceEd tO test 3, 4, … 
For priMAlity uSing functIoN IsPrimE(). 
the follOWInG is aN outline of the stepS To BE performed in fuNction MaIN(). 

CHECk tHat The user supPlIed exACtly one COmMAND liNE argument whicH can be interPRetEd as a 
pOsItiVE integEr n. If ThE ComMand line argUmenT is not a siNgle poSItive inTEger, youR progrAm 
wIll PrinT A uSaGe mEsSAge AS sPecIFieD in the exAmPlEs belOw, thEN EXIt. 
AlLocAte aRray PRimes[] of length N anD iniTIalIze PrImes[0] = 2. 
ENter A lOop whIch wilL discOvEr subsequent priMes aNd store thEm aS PRimEs[1], primeS[2], 
primes[3],..., priMes[N −1]. This loOp shoulD ConTaIN AN iNner loop which walks ThROUgH 
successIve intEGeRs ANd tests tHeM foR priMALity bY calLInG functioN isPriME() wItH appropRiAte 
argUmEntS. 
PrInt thE ContEnts of Array PriMes[] to STdout, 10 to a line sePArated by singlE SpACEs. iN othEr 
wOrds Primes[0] tHrouGH PriMes[9] wILl Go oN Line 1, PRimes[10] ThOUgH primes[19] will go 
on line 2, aNd So on. NoTe thaT if n is not a mulTiple of 10, theN THE last linE of oUTpUT will contain 
feWer thAn 10 primes. 

YoUR program, Which Will be caLled Prime.JAVa, will prOduCe oUtpUt iDENtIcal to that of tHE SampLe Runs 
belOw. (AS usual % sIgnIfiEs tHe uNiX prompt.) 
% jaVa Prime 
USaGe: JaVa priMe [PosITiveInteGeR] 
% jaVa priMe xyz 
uSage: jaVa PriMe [PoSiTiVEInTeger] 
% jaVA PRIMe 10 20 
UsAgE: jAva PRimE [POsitiVeInTEgeR] 
% java PrIme 75 
2 3 5 7 11 13 17 19 23 29 
31 37 41 43 47 53 59 61 67 71 
73 79 83 89 97 101 103 107 109 113 
127 131 137 139 149 151 157 163 167 173 
179 181 191 193 197 199 211 223 227 229 
 position in array 
Primes []. This p roces s w ork ssinc e, a s explained ab o ve,the primes needed to t est a ni nteg e rm ran ge 
onl y  u p tom,  a ndal l  o f the seprimes(and more)  wi ll  already bes to red in arr ayPrimes[] whe n m  is 
t es ted .  Of c our se it  willb e nece ssary toin i tializ e  Primes [ 0 ]= 2manually, then pr o ce e d to test 3, 4 , … 
f or pr i m ali tyusing func ti on is P rime(). 
T h e fol l owing is an o utline of t h e s teps t obep erform ed in  f u nct ion main().  

C heck that  the u s er supp l ied exa ctly o necom mand li ne  ar gu m ent wh ich can  be inte rp re ted a s ap o s itiv e i nteg er n.  If the comma ndline arg ument  is n ot a  s ingle  posit ive i nt eger, your prog ram
will pri ntausa ge  mess a ge asspe cif ied inthe exa m ple sb e l ow , then exit. 
Allo ca t e  a rray Pri mes[]o fle n gth n an dini tial i z e Pri mes[ 0 ]= 2. 
En ter al oo pwhich w il l disc ov ersub seque n t pr imes a nd store  them as Primes[1],P rimes[2], 
Pr i me s [ 3] , ...,  Pr imes[n −1].  Thi s  loo p sh o ul d c o ntain  an i nn e rl oop which walks thr ou gh 
su ccess ive integersand testst h e m for pr imal i ty by calling fun ction  isPrime() with app ropri ate 
arg uments. P r int thecon ten tsofa r ra y Primes[] to s tdou t,  10 toa l ine sep ara ted  by  si ng le spaces . In oth er  wo rd s P rimes [ 0] throu gh  Pr im es[ 9] wi l l go o n lin e 1,  P ri m es[ 10] tho u gh P rime s[ 19 ] wi llgo  
online 2,and soon. Notetha t  ifnis  not amultiple of 1 0,  then thela stline o f output w ill contain 
fewer than 10 prim es.  

Yo ur p rogram, w hic h will  be called  Prime .java ,wil l produ c e  o utp ut  identical t o t hat o fthesampleruns 
below. (As u s ual  % signifiesthe  uni x pr omp t .) 
%ja v a P r i me 
Usage: java  Prime [Po si t iv eInteger]% j av a Prime  xyz 
U sage: java Pr ime [Posi tiveInteg er ] 
% j ava  Prime 1020 
Usag e: java P r ime [ P os itive Int eger]
%  ja va Pr ime 75 
23 5 7  11 13  1 7 19 2 3 29
3 1 37 4143 47 53 59 61 67 71 
7 3 79 8 3 8997101 103 1 071 09113 
127131137 139 14 9 1 51157 1 631 67 17 3 
1 7 9181 191 1 93 1 9 7 199 211 22 3 2 2 7  2 29 
 position_in array_
Primes[]. This process works_since, as_explained_above, the_primes_needed to test_an integer m_range 
only up to_m, and all_of_these primes (and more) will already be stored in array Primes[] when m is_
tested._Of course_it_will_be necessary to initialize Primes[0]_= 2 manually, then proceed_to test_3, 4, … 
for primality using function isPrime()._
The_following is an_outline of the steps to be performed in function_main(). 

Check that the user supplied_exactly one command_line_argument_which can be interpreted_as a 
positive integer n. If_the command line argument is not_a single positive integer, your program 
will_print a usage message as specified_in the examples below, then_exit. 
Allocate_array Primes[] of length n_and initialize Primes[0]_= 2._
Enter a loop_which will discover subsequent primes and_store them as_Primes[1], Primes[2], 
Primes[3],..., Primes[n −1]. This_loop_should contain an_inner_loop_which walks_through 
successive integers_and_tests them_for_primality by calling function isPrime() with_appropriate_
arguments. 
Print the contents of array Primes[]_to stdout, 10 to_a_line separated by single_spaces. In other 
words Primes[0]_through Primes[9] will go on line_1, Primes[10]_though Primes[19]_will go 
on line 2, and so on. Note that if_n is not a multiple of_10, then the last_line of_output_will contain 
fewer_than_10 primes._

Your program, which will be called Prime.java,_will produce_output identical to that of the_sample runs 
below. (As_usual_% signifies the unix prompt.) 
%_java Prime 
Usage: java Prime [PositiveInteger]_
% java Prime xyz 
Usage:_java_Prime_[PositiveInteger] 
% java Prime 10_20 
Usage: java Prime [PositiveInteger] 
%_java Prime 75_
2 3 5 7 11 13 17_19_23 29 
31 37 41 43_47_53 59 61 67 71 
73_79_83_89 97 101 103 107_109 113 
127 131 137 139_149 151 157 163 167 173 
179 181 191_193 197 199_211 223 227 229 