I have been assigned a simple word wrap program. I think I've gotten so wrapped up in the method I'm trying to implement, but it's just not coming together.
the logic:
so I have a variable that counts the length of the line allowed "read in a width"
-I have a variable that counts the length of said list.
-I have something to check to see if the word being messed with is the first in the line or not.
-I check to see if first is true or false
-set the length of the character countering variable
if the CC is less the the width I Want, but not a first word then print a space and the word
-if it is the first word and less then the width then just print the word
and if it exceeds then print a new line and then the word.
but I am getting spill over :(!! its going a little beyond the width each time.
Expand|Select|Wrap|Line Numbers
- for (String word: words) {
- if(cc==0 ||cc ==word.length()){
- first=true;}
- if(cc !=0 && cc !=word.length()){
- first=false; }
- //if(line.trim().length()==0){out.printf("ANYBONDY HEA ME!!!");}
- cc=cc+word.length();
- if(cc>width){
- //out.printf("%d",cc);
- out.printf("%n");
- cc=word.length();
- first=true;
- }
- //if(cc==0 ||cc ==word.length()){
- // first=true;}
- if(first==true){
- out.printf("%s",word);}
- //if(cc>= width){out.printf("%n");}
- if(cc <=width&&first==false){
- out.printf(" ");
- out.printf ("%s", word);
- cc=cc+1;
- //out.printf("%d",cc);
- }
- /*
- if(cc==0 ||cc ==word.length()){
- first=true;}
- if(cc !=0 && cc !=word.length()){
- first=false; }
- if(first==true){cc=cc+word.length();
- out.printf("%s",word);}
- else{
- cc=cc+1;
- if(cc+word.length()<width){
- out.printf(" ");
- out.printf("%s",word);}
- else{
- out.printf("%n");
- cc=0;
- out.printf("%s",word);
- cc=cc+word.length();
- }
- }
- if(first){out.printf("%d",cc);}
- */
- }