题解 | #截取字符串#

截取字符串

https://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        String Str=input.nextLine();
        int k=input.nextInt();
        if (Str.length()<1||Str.length()>=1000){
            System.out.println("Str Error");
        }
        if (k<1||k>Str.length())
            System.out.println("k Error");
        String X=Str.substring(0,k);
         System.out.println(X);
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 18:13
点赞 评论 收藏
分享
uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务