The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
![]()
How would I do this:
1. Generate an array of 20 random integers from zero to nine. search for the first occurence, if any, of the number seven, and report its position in the array. 2. Repeat the computation of part a 1000 times and for each position in the array, report the number of times that the first occurence of a seven in the array is at that position. |
#2
|
||||
|
||||
![]()
1.
Code:
Random generator = new Random(); int integerArray[20]; int foundSeven=0; int i; for (i=0; i<20; i++) { integerArray[i] = generator.nextInt(); if ((integerArray[i]==7)&&(foundSeven==0)) { foundSeven = 1; println("Found the number 7 at position " + i); }// end if } // end for |
#3
|
||||
|
||||
![]()
Random generator = new Random();
int integerArray[20]; int counterArray[20]; int foundSeven=0; int i,j; for (j=0;j<1000; j++) { for (i=0; i<20; i++) { integerArray[i] = generator.nextInt(); if ((integerArray[i]==7)&&(foundSeven==0)) { foundSeven = 1; counterArray[i]++; println("Found the number 7 at position " + i); }// end if } // end for } // end for for (i=0;i<20;i++) { println("Found at position " + i + " " + counterArray[i] + " times"); } |
#4
|
|||
|
|||
![]()
Of course you'll need the 20+ MB runtime, import a million classes, and have to wait half a year for it to compile. Not that there's anything wrong with that.
![]() |
#5
|
|||
|
|||
![]()
Thanks everyone.
@Filb: I'm not going to compile it, I'm just helping out a friend. |
![]() |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|