题解 | #截取字符串#
截取字符串
https://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); int k = in.nextInt(); int len = str.length(); if(len==0 || len>1000 || k<0 || k>len){ return; } System.out.println(str.substring(0,k)); } }