I am trying to decrease the width of a text using arrays in java, but java is returning a single error -
i trying decrease width of text, , in line 19 of code java returns error cannot find symbol. here code line containing error:
public class fixedwidthprinting{ public static void print(string[] inputarray,int width){ int wordcount,charcount,extraspaces; int currentindex=0; int[] spacearray; boolean even=false; while(currentindex<inputarray.length-1){ wordcount=0; charcount=inputarray[currentindex].length(); for(int i=currentindex+1;charcount+inputarray[i].length()+1<=width;i++){ charcount+=(inputarray[i].length()+1); wordcount++; } if(wordcount==0){ spacearray=new int[1]; }else{ spacearray=new int[wordcount]; } inputarray.fill(spacearray,1);
the error:
fixedwidthprinting.java:19: error: cannot find symbol inputarray.fill(spacearray,1); ^ symbol: method fill(int[],int) location: variable inputarray of type string[]
here rest of code, perchance have error in rest of code causing java homecoming error?
extraspaces=width-charcount; if(even==false){ for(int i=0;i<spacearray.length&&extraspaces>0;i++){ spacearray[i]++; extraspaces--; } even=true; }else{ for(int i=spacearray.length-1;i>=0&&extraspaces>0;i--){ spacearray[i]++; extraspaces--; } even=false; } system.out.print(inputarray[currentindex]); currentindex++; for(int i=0;wordcount>0;i++){ for(int j=spacearray[i];j>0;j--){ system.out.print(" "); } system.out.print(inputarray[currentindex]); wordcount--; currentindex++; } system.out.println(); } } }
i thinks want utilize method fill
of java.util.arrays
do :
arrays.fill(spacearray,1);
java arrays fixed-width
No comments:
Post a Comment