I am trying to create and array that can store floating point numbers anywhere from 0.00 to 100.00. I am having a problem with the hArray, going back and fourth from it saying it needs to be initialized and trying numerous ways to do that, it tells me to change it to doublehArray[] = null;. but when i try that no valuse are stored in it.
the problem occurs between line 3 and also line 27 which is hArray[i}] = rnum
Ignore the print line command i was just using those to check errors.
public static void main(String[] args) {
int i;
double hArray[];
int nYears = 0, y = 0;
double rMax = 0.00,rMin = 100.00;
get input check if between 1-80
while(y == 0){
String userData = JOptionPane.showInputDialog
("Enter number of years");
nYears = Integer.parseInt(userData);
if (nYears > 1 && nYears <= 80 )
y = 1;
}
reset y to = 0
y = 0;
System.out.println("step1 "+ nYears+ " "+ y);
while(y <= nYears){
System.out.println("step2");
for(i = 0; i < 12; i++){
System.out.println("step3");
Random rand = new Random();
double rNum = rand.nextFloat() * (rMax - rMin) + rMin;
hArray[i] = rNum;
System.out.println("step4" + hArray[i]);
}
Aucun commentaire:
Enregistrer un commentaire