我正在尝试编写允许我在给定索引处删除字符串的特定字符的代码。但是,每当我在“原始”中使用空格时,都会出现一系列错误。我有以下。
import java.util.*;
public class Test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in);
System.out.println("Enter a word");
String raw = reader.next();
System.out.println("Enter the number of the letter you would like to remove");
int x = reader.nextInt();
StringBuffer sbf = new StringBuffer(raw);
sbf.deleteCharAt(x-1);
String fixed = sbf.substring(0);
System.out.println(fixed);
}
}