题解 | #截取字符串#
截取字符串
https://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
import java.util.*;
// 没什么好说的
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) {
String str = in.nextLine();
if (str == null || str == "") break;
String lenS = in.nextLine();
int len = Integer.parseInt(lenS);
System.out.println(str.substring(0, len));
}
}
}
查看1道真题和解析