HomeWork2:Tasks(1-3,5-7)#8
HomeWork2:Tasks(1-3,5-7)#8yarikpavlin wants to merge 10 commits intoChangeRequest:masterfrom yarikpavlin:master
Conversation
| return ""; | ||
| public static String makeTags(String tag, String text) | ||
| { | ||
| return "<"+tag+">"+text+"</"+tag+">"; |
There was a problem hiding this comment.
It's OK, but try to solve this task with String.format() method.
| return ""; | ||
| else | ||
| if (s.length() <= 2) { | ||
| return s.substring(0); |
There was a problem hiding this comment.
there is no need for such call. just return s.
| return s.substring(0); | ||
| } | ||
| return s.substring(0, 2); | ||
| } |
There was a problem hiding this comment.
Also you if clauses could be combined into one:
if (s == null || s.length <=2){
return s;
}There was a problem hiding this comment.
But, if string equals null, we must return null , not s
There was a problem hiding this comment.
if s will be equal to null - you'll return value of s - null. There will be no difference between returning s(that is equal to null) and null.
For example:
public class Test(){
public static void main(String[] args){
String nullValueString = null;
System.out.println(null); // will print 'null'
System.out.println(nullValueString); // will print 'null'
System.out.println(nullValueString == null); // will print 'true'
}
}| if(s1.length() < s2.length()) | ||
| return s1+s2+s1; | ||
|
|
||
| return s2+s1+s2; |
There was a problem hiding this comment.
It's OK, but format your code before submitting.
In IDEA you can use CTRL+ALT+L shortcut.
| if(arr == null) | ||
| return 0; | ||
| for (int anArr : arr) { | ||
| if (anArr % 2 == 0) |
There was a problem hiding this comment.
It's OK, but there is faster way to check if number is Even or Odd. Read about parity bit.
| return ""; | ||
| public static String makeTags(String tag, String text) | ||
| { | ||
| return String.format("%1$s%2$s%3$s%4$s%5$s%2$s%3$s", "<", tag, ">", text, "</", tag, ">"); |
There was a problem hiding this comment.
You can print any constant values in pattern, for example:
String.format("<%1$s>", "tag") will print "<tag>".
| else | ||
| if (s.length() <= 2) { | ||
| return s; | ||
| } |
There was a problem hiding this comment.
If s will be equal to "" than it's length will be less than 2 - so there is no need for such check.
Other Tasks will be done soon