Conversation
| String substring = shortstr.substring(0); | ||
| return substring; | ||
| } | ||
|
|
There was a problem hiding this comment.
It's quite uncommon way to solve this task.
Actually, there is no need for StringBuilder here - you can just use substring method of String.
Also, you can move length check to null-check, so that you'll check string for null and for length<2 and just return s.
| String closetag = "</" + tag + ">"; | ||
| String html = opentag + text + closetag; | ||
|
|
||
| return html; |
There was a problem hiding this comment.
It's OK, but IMO, it's better to solve this task with StringBuilder and the best solution will be using String.format().
| return html; | ||
|
|
||
| return String.format("%s", "<" + tag + ">" | ||
| + text + "</" + tag + ">"); |
There was a problem hiding this comment.
You are almost done.
Now, there is no need to use only one %s in format.
Also, you can combine format with any symbols, so that it should look like: <%s>%s...
| if (i > 0 && i >= s.length()) { | ||
| i = i - s.length(); | ||
| } | ||
| return String.valueOf(s.charAt(i)); |
There was a problem hiding this comment.
Your implementation pass all tests, but you've used lots of unnecessary operations and it'll be quite slow (due to additional usage of Math and StringBuilder.
Try to solve this task from Math point of view - you just need to calculate char index properly and this could be done using % operator.
There was a problem hiding this comment.
i didn't have any idea. what do you mean about use % operator ?
There was a problem hiding this comment.
% - is modulus operator in Java.
For example for positive index, result index on which you can get needed char could be calculated in following way:
int index %=s.length().
| return a[0] == b[0] || a[a.length - 1] == b[b.length - 1] || a[0] == b[b.length - 1] || a[a.length - 1] == b[0]; | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
And again. It do pass all tests, but it's again to complicated.
Why do you need this if clause ? Also there is no need for lengthA and lengthB vars (or you should reuse them everywhere).
By the task description: you'll 100% have arrays with length>=1.
|
|
||
| return false; | ||
|
|
||
|
|
There was a problem hiding this comment.
- you don't need
ifclause, as result of your expression isboolean- you can just return it. - you should cover one more case - last
ais equal to lastb.
| for (int i = arr.length - 1; i >= 0; --i) { | ||
| reverseArr[i] = arr[n]; | ||
| n++; | ||
| } |
There was a problem hiding this comment.
You can create more complex for condition:
for (int i = arr.length - 1, n=0; i >= 0 && n<arr.length; i--, n++) {
reverseArr[i] = arr[n];
}But, actually, this task could be solved with only one index variable.
| } | ||
| int n = 0; | ||
| for (int i = arr.length - 1; i >= 0; --i) | ||
| if (arr[i] % 2 == 0 || arr[i] == 0) { |
There was a problem hiding this comment.
There is no need for you additional condition arr[i]==0 cause even when arr[i] will be 0 - 0%2 ==0 will return true.
|
@dianasinenchenko Please remove wrong |
|
@dianasinenchenko What about task 9 and task 10 ? |
|
@xSAVIKx i try writing correct pattern for task 9. will be today |
|
@dianasinenchenko What exact problems do you have ? If you need any assistance - it's better to ask questions via Gitter |
| StringBuilder surl = new StringBuilder(); | ||
| if (murl.find()){ | ||
| surl.append(murl.group()).append("\n"); | ||
| return new String[]{surl.toString()}; |
There was a problem hiding this comment.
Try to avoid such naming.
Characters are free of charge now and you can easily create names with any length.
Also, follow lowerCamelCase for variables names.
Following names would be better:
url -> regexp
purl -> urlPattern
murl -> urlMatcher
surl -> result.
Also, you need to provide String[3] array and with current implementation you'll supply String[1] array, as surl.toString() will create one String object.
| Matcher mhost = phost.matcher(URL); | ||
| Matcher mport = pport.matcher(URL); | ||
|
|
||
| String url =" ( (?<=\\:\\/\\/) [\\w] +.) ? ((?<= \\/\\/) [\\w\\d.-_] +.) ((?<=\\: ) [\\d] ) "; |
There was a problem hiding this comment.
I'm pretty sure, that your regexp is not correct.
Schema could contain only [a-zA-Z0-9].
Host could contain [a-zA-Z0-9-_.]
Port could have more than 1 number
No description provided.