java - print first array element when it ends -


as topic states , previous post

which requires me print 4 consecutive numbers in array locations

i have managed understand code given me. fast snail comment made me thought program thoroughly , indeed got me thinking on how make array print it's first location's element again.

as e.g (" note " array size 20) array location given me 18, program have print elements in location 19, 20, 1 ,2 . have managed understand on how print elements in location 19 , 20 have no idea how program print it's first position.

thanks once again in advanced given!

use mod operation length of array.

18 % 20 = 18
19 % 20 = 19
20 % 20 = 0 (first element of array)
21 % 20 = 1

int firstprint = 18;//or random value  for(int = firstprint; < firstprint + 4; i++) {     system.out.println(myarray[firstprint % myarray.length]); }  

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -