java - Only put a certain number of lines in a char array -
i have file 2939 lines, , trying save 5 lines in 1 index of 2d char array. so,
char [][] myarray; myarray[0] = {} //<--char array of first 5 lines myarray[1]= //char array of next 5 lines
the way implementing is:
int countlines=0; while (sc.hasnext() countlines <5) { //sc scanner //read each line , append string builder //then convert stringbuilder char array , //store in myarray[0] countlines++; }
i stuck on part of storing next 5 lines in myarray[1]. appreciated. thanks!
you can try this
while(sc.hasnext()) { if(countlines < 5) { //store in myarray[0] } else if(countlines >= 5 && countlines < 10) { //store in myarray[1] } countlines++; }
Comments
Post a Comment