PDA

View Full Version : one error in program, cant figure out what it is


toejam
05-13-2009, 01:43 AM
Does anyone know what this means?
It says my error is this:
43: cannot find symbol
symbol : method deleteCharAt(int,int,int)
location: class java.lang.StringBuilder
stringBuilder.deleteCharAt(8, 11, 14);

1 error




import java.util.Scanner;

public class Java {

//Main Method
public static void main(String[] args)throws Exception {

java.io.File file = new java.io.File("Welcome.txt");
Scanner input = new Scanner(file);

//Create a Scanner
String s = input.nextLine();
System.out.println( s );

//Invoke the countLetters method to count each letter
int[] counts = countLetters(s.toLowerCase());
for (int i=0; i < counts.length; i++) {
if (counts[i] != 0)
System.out.println((char)('a' + i) + " appears " + counts[i] + ((counts[i] == 1) ?
" time" : " times"));
}
}

//Count each letter in the string
public static int[] countLetters (String s) {
int[] counts = new int[26];

for (int i=0; i < s.length(); i++) {
if (Character.isLetter(s.charAt(i)))
counts[s.charAt(i) - 'a']++;
}
return counts;
}

//Create a new string to remove all the spaces between words
public static String Remove(String s) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (Character.isLetterOrDigit(s.charAt(i))) {
stringBuilder.deleteCharAt(8, 11, 14);
}
}
return stringBuilder.toString();

}


}

Aradon
05-13-2009, 02:36 AM
DeleteCharAt only takes one input, the index:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html#deleteCharAt(int)