java - Turning a string into multiple arrays? -


i'm student learning java (just started year. graduated can't ask high school teacher help, either), , need on how turn string multiple arrays(?).

however, after stuck (because can't find way break down string purposes).

the file read this

input: first line number of cases. each case first line susan’s work schedule, , second line jurgen’s work schedule. work schedules date of month (1-30) work. third line size of initial tv.

the file in question:

 3  2 5 10  2 4 10  60  2 4 10  2 5 10  60  1 2 3 4 7 8 10 12 14 16 18 20 24 26 28 30  1 2 3 6 9 10 17 19 20 21 22 23 25 27 28 29  20 

i'm not sure how go this. i've tried .split(), seems work on first row in string. help/tips might have appreciated!

hey got great solution you.

just make class store each student's data like

  import java.util.list;    public class student {  private int noofcases; private list<string> workschedule; private list<string> initialtv;  //getter setters } 

then this...

public static void main(string[] args) {      //3 students reading 9 lines     //susan,  jurgen , ;)     student[] students = new student[3];      int linesread = 0;      string aline = null;      // read each line through aline     (student student : students) {          //use buffered/scanner classes reading input(each line) in aline         while (aline != null) {             ++linesread;             if (linesread == 1) {                 student.setnoofcases(integer.valueof(aline));                 ++linesread;             } else if (linesread == 2) {                 student.setworkschedule(arrays.aslist(aline.split(" ")));                 ++linesread;             } else if (linesread == 3) {                 student.setinitialtv(arrays.aslist(aline.split(" ")));             } else {                 linesread = 0;             }         }     } } } 

if need read more lines/more student's records, resize student array!!


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -