Hello
I'm trying to make a random number generator to work out probability and chance, although it keeps coming up with an ArrayIndexOutOfBoundsException on line 41(roughly).
I would be really greatful if you could help!
thx
p.s.This is not for school
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package randomiser;
import javax.swing.*;
/**
*
* @author Toby
*/
public class Main extends JFrame{
public Main(){
super("Randomizer");
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String x = JOptionPane.showInputDialog("How many possablilities:");
String y = JOptionPane.showInputDialog("How many tries");
int poss = Integer.parseInt(x);
int times = Integer.parseInt(y);
int[] results = new int[poss];
for(int i = 0; i < poss; i++){
results[i] = 0;
}
String[] comps = new String[poss];
for(int i = 0; i < times; i++){
int result = (int)(Math.random()*poss);
int z = results[result];
z++;
}
for(int z = 0; z <= poss ;z++){
String whatever = z + " : " + results[z];
comps[z] = whatever;
}
JList list = new JList(comps);
JPanel pane = new JPanel();
JScrollPane scroll = new JScrollPane(list);
pane.add(scroll);
add(pane);
setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main x = new Main();// TODO code application logic here
}
}