Question on do while loop
I feel like I'm beating my head against a wall.
In the code below I am trying to create a new "noteLine" if an element in a string array has a length of 45 or greater. However, in addition to this I am needing to create a new "noteLine" for each chunk of 45 chars.
Any help or direction would be greatly appreciated.
Here is my code:
public class SplitTestCode {
public static void main (String args[]) {
String note = "Case is significant in identifiers in Java, so if and If are considered to be quite different. \n"
+ "The language has a small set of reserved words such as if, while, etc. \n"
+ "They are all sequences of lower-case letters. \n"
+ "The Java language places no restrictions on what names you use for functions, variables, classes, etc. \n"
+ "However, there is a standard naming convention, which all the standard Java libraries follow, and which you must follow in this class.";
String[] notes = note.split("\n");
//System.out.println("Notes length is " + notes.length);
String noteLine = null;
for (int i = 0; i < notes.length; i++) {
noteLine = notes[i];
//System.out.println("Here is my note: " + noteLine + "\n" + "Length of this note: " + notes[i].length());
do {
if (notes[i].length() < 45){
noteLine = notes[i].substring(0, notes[i].length()-1);
System.out.println("Here is my note: " + noteLine);
}
else{
noteLine = notes[i].substring(0, 45);
if (notes[i].length() > 45) {
noteLine = notes[i].substring(45, notes[i].length()-1);
}else{
noteLine = null;
}
System.out.println("Here is my note: " + noteLine);
}
}while (notes[i] != null);
}
}
}
|