I'm having some trouble with a program that I'm writing. What I need to do is generate random numbers from 0-9, 100 times, and then print the outcome of how many times each numbers is generated. I have to put this all into arrays, one holding the 100 random numbers, and another holding the 'x' times each number was printed.
Here is my code so far:
import java.applet.Applet;
import java.awt.*;
public class RandomTölur extends Applet {
TextArea t;
int[] random;
int[] hveOft;
int i;
int[] k = hveOft;
public void init()
{
t = new TextArea(5, 25);
this.add(t);
random = new int[101];
random[0] = 0;
for(i=1; i<100; i++)
{
random[i] = random[i];
}
for(int k=1; k<10; k++)
{
t.appendText("Talan " + k + " kom " + random[i] + " sinnum" + "\n");
}
}
}
When it prints out "Talan 'k' kom 'i' sinnum", that means "the number 'k' was printed 'i' times.
The problem I'm having is that it doesnt print out how many times each number came out.
Is there anyone who can spot my error?
Ps. sorry if this post is unproffessional or something, this is my first post on Stackoverflow.
Thanks in advance! :)
Ps. I've figured this out thanks to the help of you guys, so thanks everyone who reply'd to this :) Much appriciated.
this.random[this.i] = (int)(Math.random() * 10);will help. As will starting your final loop from 0, not 1