java题目截取字符串

 

 

 1 import java.io.*;
 2 import java.util.*;
 3 
 4 public class Main{
 5     public static void main(String[] args) throws IOException {
 6         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 7         
 8         String line = "";
 9         while((line = br.readLine()) != null) {
10             int n = Integer.parseInt(br.readLine());
11             String newLine = line.substring(0,n);  //生成子字符串从索引0到n,不包含结尾
12             System.out.println(newLine);
13         }
14     }
15 }

 

posted @ 2022-03-05 17:04  海漠  阅读(16)  评论(0编辑  收藏  举报