Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

HomeWork2:Tasks(1-3,5-7) #8

wants to merge 10 commits into from

Conversation

yarikpavlin
Copy link

Other Tasks will be done soon

@xSAVIKx xSAVIKx self-assigned this Nov 25, 2016
return "";
public static String makeTags(String tag, String text)
{
return "<"+tag+">"+text+"</"+tag+">";
Copy link
Member

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);
Copy link
Member

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);
}
Copy link
Member

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;
}

Copy link
Author

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

Copy link
Member

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;
Copy link
Member

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)
Copy link
Member

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, ">");
Copy link
Member

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;
}
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants