2013-09-28 3 views
-2

주어진 색인에서 특정 문자를 제거 할 수있는 코드를 작성하려고합니다. 그러나 "raw"공간을 사용할 때마다 일련의 오류가 발생합니다. 다음과 같은 내용이 있습니다.문자열의 공백으로 인해 오류가 발생합니다.

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); 
    } 
} 
+8

어떤 오류가 있습니까? ... –

답변

1

Scanner.next()는 다음 토큰 (단어)을 반환합니다. 아마도 Scanner.nextLine()을 대신 사용하려고합니다.

+1

'String fixed = sbf.substring (0);'이 (가) 실제로있을 필요는 없습니다. 'toString'이 할 것입니다. – Rhys

관련 문제