-
Notifications
You must be signed in to change notification settings - Fork 10
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
ht Diana #3
base: master
Are you sure you want to change the base?
ht Diana #3
Changes from 11 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 |
---|---|---|
|
@@ -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); | ||
|
||
|
||
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 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)); | ||
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 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 ? 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.
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]); | ||
|
||
|
||
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.
|
||
} | ||
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,19 @@ | ||
package school.lemon.changerequest.java.introduction.hw2; | ||
|
||
|
||
import com.sun.xml.internal.fastinfoset.util.CharArray; | ||
|
||
public class Task6 { | ||
public static int[] reverse(int[] arr) { | ||
return null; | ||
if (arr == null) { | ||
return null; | ||
} | ||
int reverseArr[] = new int[arr.length]; | ||
int n = 0; | ||
for (int i = arr.length - 1; i >= 0; --i) { | ||
reverseArr[i] = arr[n]; | ||
n++; | ||
} | ||
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; | ||
} | ||
} |
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
%s
in format.Also, you can combine format with any symbols, so that it should look like:
<%s>%s...