-
Notifications
You must be signed in to change notification settings - Fork 9
ht Diana #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ht Diana #3
Changes from all commits
3a2d2c4
5fa2973
59786c3
dc94af1
e1d526d
6cac7fc
b096078
ca9406c
7b2f9bd
76c2630
f189030
c70745e
0a8c370
238deb2
8fd98d1
22ea85d
7bd5d21
1b5a143
80f5ff3
73057ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| package school.lemon.changerequest.java.introduction.hw2; | ||
|
|
||
| import java.util.Formatter; | ||
|
|
||
| public class Task1 { | ||
| public static String makeTags(String tag, String text) { | ||
| return ""; | ||
|
|
||
|
|
||
| return String.format("%s", "<" + tag + ">" | ||
| + text + "</" + tag + ">"); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,23 @@ | ||
| package school.lemon.changerequest.java.introduction.hw2; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class Task10 { | ||
| public static String trim(String text) { | ||
| if (text == null) { | ||
| return null; | ||
| } | ||
| // "" | ||
| String stext = "(((?<=[\\s])[\\w]+.*[^\\s]+)|([\\w]).*[^\\s])"; | ||
|
|
||
|
|
||
| Pattern ptext = Pattern.compile(stext); | ||
| Matcher mtext = ptext.matcher(text); | ||
| StringBuilder surl = new StringBuilder(); | ||
| if (mtext.find()) { | ||
| return mtext.group(); | ||
| } | ||
| return ""; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,13 @@ | |
|
|
||
| public class Task2 { | ||
| public static String firstTwo(String s) { | ||
| return ""; | ||
|
|
||
|
|
||
| if (s == null || s.length() < 2) | ||
| return s; | ||
|
|
||
| return s.substring(0, 2); | ||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's quite uncommon way to solve this task. Also, you can move length check to null-check, so that you'll check string for null and for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it means like this ?6cac7fc |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,26 @@ | |
|
|
||
| public class Task4 { | ||
| public static String charAt(String s, int i) { | ||
| return ""; | ||
|
|
||
|
|
||
| if (i < 0 && Math.abs(i) <= s.length()) { | ||
| StringBuilder s1 = new StringBuilder(s); | ||
| s1.reverse(); | ||
| i = Math.abs(i) - 1; | ||
| return String.valueOf(s1.charAt(i)); | ||
| } | ||
|
|
||
|
|
||
| if (i < 0 && Math.abs(i) > s.length()) { | ||
| StringBuilder s1 = new StringBuilder(s); | ||
| s1.reverse(); | ||
| i = s.length() - (Math.abs(i) - 1); | ||
| return String.valueOf(s1.charAt(i)); | ||
| } | ||
|
|
||
| if (i > 0 && i >= s.length()) { | ||
| i = i - s.length(); | ||
| } | ||
| return String.valueOf(s.charAt(i)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your implementation pass all tests, but you've used lots of unnecessary operations and it'll be quite slow (due to additional usage of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i didn't have any idea. what do you mean about use % operator ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, interesting. thx |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ | |
|
|
||
| public class Task5 { | ||
| public static boolean commondEnd(int[] a, int[] b) { | ||
| return false; | ||
|
|
||
|
|
||
| return (a[0] == b[0] || a[0] == b[b.length - 1] || a[a.length - 1] == b[0] || a[a.length - 1] == b[b.length - 1]); | ||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And again. It do pass all tests, but it's again to complicated. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,17 @@ | ||
| package school.lemon.changerequest.java.introduction.hw2; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| public class Task6 { | ||
| public static int[] reverse(int[] arr) { | ||
| return null; | ||
| if (arr == null) { | ||
| return null; | ||
| } | ||
| int reverseArr[] = new int[arr.length]; | ||
| for (int i = arr.length - 1, n = 0; i >= 0 && n < arr.length; i--, n++) { | ||
| reverseArr[i] = arr[n]; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create more complex 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. |
||
| return reverseArr; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,27 @@ | ||
| package school.lemon.changerequest.java.introduction.hw2; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class Task9 { | ||
| public static String[] extractData(String URL) { | ||
| if (URL == null) { | ||
| return new String[]{"", "", ""}; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| String url =" ( (?<=\\:\\/\\/) [\\w] +.) ? ((?<= \\/\\/) [\\w\\d.-_] +.) ((?<=\\: ) [\\d] ) "; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure, that your regexp is not correct. |
||
| Pattern purl = Pattern.compile(url); | ||
| Matcher murl = purl.matcher(URL); | ||
| StringBuilder surl = new StringBuilder(); | ||
| if (murl.find()){ | ||
| surl.append(murl.group()).append("\n"); | ||
| return new String[]{surl.toString()}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to avoid such naming. |
||
| } | ||
|
|
||
|
|
||
| return new String[]{"", "", ""}; | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are almost done.
Now, there is no need to use only one
%sin format.Also, you can combine format with any symbols, so that it should look like:
<%s>%s...