vendredi 20 février 2015

How to execute Two while loops containing the same condition in Java?


Vote count:

0




Hello java programmars,


I am using the java OpenCSV library to read and then write a new file. The requirement is to write a "@" symbol at the end of each line except the last line. I am succeeded with adding "@" after each line but the last line must not contain "@". A part of my java program program is as follows:



//A part of my java code
String[] endOfLine;
String[] nextLine;
int endLine = 0;
int lineNumber = 0;
//To get how many line are in the input file
while ((endOfLine = reader.readNext()) != null) {
endLine++;
}
//for 8 lines endLine is 8 here - which is ok
//Now I want to pass this in next while loop - which is also ok

while ((nextLine = reader.readNext()) != null) {
lineNumber++;
channel_temp = nextLine[5];

if (lineNumber == endLine)
{
//Build a new string with all our required data
String newdata = channel_temp;
writer.writeNext(newdata);
System.out.println(newdata);

}
else
{
String newdata2 = channel_temp+"@";
writer.writeNext(newdata2);
System.out.println(newdata2);
}
}
System.out.println("lineNumber: " + lineNumber);
System.out.println("endLine: " + endLine);


The program shows the output as:



lineNumber: 0
endLine: 8


So, why my while loop is not upadating lineNumber value? In which part I am wrong?



asked 1 min ago







How to execute Two while loops containing the same condition in Java?

Aucun commentaire:

Enregistrer un commentaire