直接从头开始遍历加入就行了吧,不管了,反正AC了。

import java.util.*;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            String string = scanner.next();
            int n = scanner.nextInt();
            StringBuffer sBuffer = new StringBuffer();
            for(int i = 0; i < n; i++) {
                sBuffer.append(string.charAt(i));
            }
            System.out.println(sBuffer.toString());
        }
    }
}