printing - How to print out a line in a textfile into 2 different lines on console Java -
public static faq_alisa_qna[] oipreadquestion(){ string questiona1,thisuser; int indexquestion; string [] entrydetails; faq_alisa_qna [] entries = new faq_alisa_qna[100]; //read file = "activities.txt". file file = new file ("readoip.txt"); int count = 0; try{ scanner sc = new scanner(file); //do while there next line in file. while(sc.hasnextline()){ string line = sc.nextline(); entrydetails = line.split(";"); // index = entrydetails[0]; indexquestion = integer.parseint(entrydetails[0]); thisuser = entrydetails[1]; questiona1 = entrydetails[2]; //object store values of entry. faq_alisa_qna = new faq_alisa_qna(); // a.index = integer.parseint(index); a.indexquestion = indexquestion; a.thisusername = thisuser; a.questiona1 = questiona1; entries [count] = a; count++; } }catch(filenotfoundexception fnfe){ system.out.println(fnfe.getmessage()); } faq_alisa_qna [] allquestions = new faq_alisa_qna [count]; for(int = 0; < count; i++){ allquestions[i] = entries[i]; } return allquestions; } public static faq_alisa_qna[] oipreadanswers(){ string indexanswer, answer11, thisuser; string [] answerdetails; faq_alisa_qna [] answers = new faq_alisa_qna[100]; //read file = "activities.txt". file thisfile = new file ("ansreadoip.txt"); int count1 = 0; try{ scanner sc1 = new scanner(thisfile); //do while there next line in file. while(sc1.hasnextline()){ string line = sc1.nextline(); answerdetails = line.split(";"); // index = entrydetails[0]; indexanswer = answerdetails[0]; thisuser = answerdetails[1]; answer11 = answerdetails[2]; //object store values of entry. faq_alisa_qna = new faq_alisa_qna(); // a.index = integer.parseint(index); a.indexanswer = integer.parseint(indexanswer); a.thisusername = thisuser; a.answer11 = answer11; answers [count1] = a; count1++; } }catch(filenotfoundexception fnfe){ system.out.println(fnfe.getmessage()); } faq_alisa_qna[] allanswers = new faq_alisa_qna[count1]; for(int = 0; < count1; i++){ allanswers[i] = answers[i]; } return allanswers; } public static void oipprintqna(){ faq_alisa_qna [] allquestions = oipreadquestion(); faq_alisa_qna [] allanswers = oipreadanswers(); system.out.println("organization in project work"); system.out.println("============================="); for(int = 0; < allquestions.length; i++){ system.out.println( allquestions[i].indexquestion + "-" + "question" + ":"); system.out.println(allquestions[i].thisusername + ":" +allquestions[i].questiona1); system.out.println(" "); for(int j = 0; j < allanswers.length; j++){ if(allquestions[i].indexquestion == allanswers[j].indexanswer){ system.out.println("answer question "+ + allanswers[j].indexanswer+ ":" ); system.out.println(allanswers[j].thisusername+ ":" +allanswers[j].answer11); system.out.println(" "); } } } }
//so have read answers , questions , saved qns , answers in 2 different text files. because have add functions never put here cuz qn not related that. wanna know how print out qn , answer in 2 lines if qn long can print out in 2 lines//
so these how text files like: readoip.txt
1;shafiq;how organize time when you're juggling many project work , assignments on same day? best answer:the best solution planning or schedule time wisely. write in calendar beforehand work going assignment. 2;rohannah;does having timetable works finish project on time? 3;lymeoww;is task allocation important organized in project work?
ansreadoip.txt
1;andy23;the best solution planning or schedule time wisely. write in calendar beforehand work going assignment .2; having timetable project works? //for example line, print out long on console// 2;betty23;of course does! 1;ying qian;just organize lorh 3;lymeoww;yes, important!
//refer picture//
Comments
Post a Comment