-2
我正在嘗試編寫代碼,使我可以刪除特定索引處字符串的特定字符。但是,每當我在「原始」中使用空格時,我都會遇到一系列錯誤。 我有以下。字符串中的空格導致錯誤
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);
}
}
什麼錯誤?... –