I am trying to decrease the width of a text, and in line 19 of my code java returns the error cannot find symbol. Here is my code up to the line containing the 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 is the rest of the code, could I possibly have an error in the rest of my code that is causing java to return this 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 you want to use the method
fill
ofjava.util.Arrays
Do it like this :