java - Storing in Array from methods -
im trying double in array. question have store results user input in array. example, ask user initial population, first day , increase rate. calculate increase in population. meant store increase in population in array, can help? stuck. heres code:
public static void main(string[] args) { scanner kd = new scanner(system.in); double temppop, temprate; int tempday; double growth; system.out.println("enter population: "); temppop = kd.nextdouble(); system.out.println("enter days: "); tempday = kd.nextint(); system.out.println("enter rate: "); temprate = kd.nextdouble(); final double scores = tempday; double scores [] = new double[(int) scores]; for(int = 0; < scores; i++) { scores[i] = getrate(temppop, tempday, temprate); system.out.println(scores[i]); } } public static double getrate(double temppop, int tempday, double temprate) { double popul, pops = 0; (double day = 0; day <= tempday; day++) { popul = temppop + (temppop * temprate/100); pops = day*popul; } return pops; }
}
this output: (only example)
enter population: 10 enter days: 2 enter rate: 3 10.3 10.3
is want? rather passing value of tempday loop, never changes, pass value of in instead (which increases until tempday value met).
double scores [] = new double[tempday]; for(int = 0; < tempday; i++) { scores[i] = getrate(temppop, + 1, temprate); system.out.println(scores[i]); }
this way, following sample data, output be:
enter population: 10 enter days: 2 enter rate: 3 10.3 20.6
Comments
Post a Comment