java - Please help me understand Arrays -
i in 4th week of programming , teacher moving quickly. confused. vaguely understand arrays is. teacher wants create array (a double) has 50 elements, need loop through array , have first 25 have if statement set index squared, else 3x index. need print out 10 per line. way on head , of course teacher not going available saturday or sunday (it due sunday). after got clarification on teacher wanted wednesday. have been going crazy trying figure out how this. not asking answer, solid direction.
correspondence email teacher while asking clarification."you’re on right track not quite there. index variable isn’t set number; reference value in array. in statement: array[count] = 5; count index variable , value basing our calculations on. since changes, our output more like:
- 0 1 4 9 16 25 36 49 64 81
- 100 121 .. .. .. .. .. .. .. ..
- .. .. .. .. .. 75 78 81 84 87
- .. .. .. .. .. .. .. .. .. ..
- .. .. .. .. .. .. .. .. .. ..
notice should full 10 line making line 3 have 5 each of calculations together."
first part
double[] arr=new double[50]; for(int i=0;i<25;i++) arr[i]=i*i;
second part
for(int i=25;i<arr.length;i++) arr[i]=3*i;
third part
for(int i=0;i<arr.length;i++) { if((i%10==0)&&i!=0) system.out.println(arr[i]+" "); else system.out.print(arr[i]+" "); }
i'm not sure if understood first part squared index, second double index, third printing array, notice after every 10 printings goes new line.
Comments
Post a Comment