-
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
HomeWork2:Tasks(1-3,5-7) #8
base: master
Are you sure you want to change the base?
Conversation
return ""; | ||
public static String makeTags(String tag, String text) | ||
{ | ||
return "<"+tag+">"+text+"</"+tag+">"; |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no need for such call. just return s
.
if (s.length() <= 2) { | ||
return s.substring(0); | ||
} | ||
return s.substring(0, 2); | ||
} |
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.
Also you if clauses could be combined into one:
if (s == null || s.length <=2){
return s;
}
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.
But, if string equals null, we must return null , not s
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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