华为机试-HJ46 截取字符串

112 阅读1分钟

题目

image.png

www.nowcoder.com/practice/a3…

我的题解

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String str = bf.readLine();
        Integer num = Integer.parseInt(bf.readLine());
        bf.close();
        System.out.println(str.substring(0, num));
    }
}

image.png