I must start off by saying that I am new to Java. I have done this in C before but I don't really know how to finish this code in Java. I am learning it by myself, from what I get from the documents on Stackoverflow and NetBeans. I am doing a small exercise that i found on RosettaCode to learn more on Java but I need someone to help me with the coding.
1.The program needs to allow the user to select the values for fact, constant, modulus and a starting seed number.
-
It should generate 1000 random numbers between 0 and 9 using those values.
-
Store the number of times each number is generated in an array.
-
Output the distribution of the numbers at the end.
Here is what i've done till now but i've only got the user to input the information till now, so, i'm very far from having achieved number 2, 3 and 4. Help me complete it please, provide me with the steps to follow. I am blocked here. Thank you.
int fact;
int constant;
int modulus;
int seednumber;
Scanner scan = new Scanner(System.in);
System.out.println("Input Fact: ");
fact = scan.nextInt();
System.out.println("Input Const: ");
constant = scan.nextInt();
System.out.println("Input M: ");
modulus = scan.nextInt();
System.out.println("Input Seed: ");
seednumber = scan.nextInt();
int [] arrayBox;
arrayBox = new int [10];
for (int i=0; i<10; i++){
arrayBox[i]=0;
}
int noOfNumberGenerated=0;
while (noOfNumberGenerated<1000){
seednumber=(((fact*seednumber)+constant)%modulus);
Aucun commentaire:
Enregistrer un commentaire