package com.codegym.task.task22.task2202;
/*
Find a substring
*/
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) {
System.out.println(getPartOfString("CodeGym is the best place to learn Java."));
}
public static String getPartOfString(String string)
{
try
{
ArrayList<String> list = new ArrayList<>(5);
String totalString = string;
for (int i =0;i<4;i++)
{
totalString = totalString.substring(totalString.indexOf(' ')+1);
list.add(totalString.substring(0,totalString.indexOf(' ')));
}
return list.get(0)+" "+list.get(1)+" "+list.get(2)+" "+list.get(3);
}
catch (Exception e)
{
throw new StringTooShortException();
}
}
public static class StringTooShortException extends RuntimeException{
}
}
I don't know why my solution can't pass the test.
正在讨论
评论 (2)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Lisa
23 九月 2021, 15:36
Test, test, test a lot, especially test the borderline cases like:
That's what CGs doing, too... yeah, yeah 😜🤪 +1
AKUN
25 九月 2021, 00:42
Thank you very much.
0