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

1-8,10 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

public class Task1 {
public static String makeTags(String tag, String text) {
return "";


return "<"+tag+">"+text+"</"+tag+">";
Copy link

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 use String.format()

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public class Task10 {
public static String trim(String text) {
return "";

if(text==null){return null;}
String resultString = text.trim();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an option. Task was do it without default trim.



return resultString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

public class Task2 {
public static String firstTwo(String s) {
return "";
if(s.length()<=2){return s;}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add null check too.

else return s.substring(0,2);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

public class Task3 {
public static String comboString(String s1, String s2) {
return "";
}
if(s1==null){s1="null";}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format your code.

if(s2==null){s2="null";}
if(s1.length()>=s2.length()){
return s2+s1+s2;}
else return s1+s2+s1;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

public class Task4 {
public static String charAt(String s, int i) {
return "";
int realCharAt=0;
if (i>=0&& s.length()>=i){realCharAt=i;}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (i>s.length()){realCharAt=i%(s.length());}
else if (i<0){realCharAt=s.length()+(i%(s.length()));}
if(realCharAt==s.length()){realCharAt=0;}
return s.substring(realCharAt,realCharAt+1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class Task5 {
public static boolean commondEnd(int[] a, int[] b) {
if (a[0] == b[0]||a[a.length-1]==b[0]||a[0]==b[b.length-1]||a[a.length-1]==b[b.length-1]) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract to variables a[0] etc.


return true; }

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

public class Task6 {
public static int[] reverse(int[] arr) {
return null;
if (arr==null){return null;}
for(int i=0;i<(arr.length)/2;i++){

int temp=arr[i];
arr[i]=arr[arr.length-1-i];
arr[arr.length-1-i]=temp;
}
return arr;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package school.lemon.changerequest.java.introduction.hw2;



public class Task7 {
public static int countEvens(int[] arr) {
return 0;
int count =0;
if(arr==null){return 0;}
for(int i=0; i<arr.length; i++){
if (arr[i]%2==0||arr[i]==0){count=count+1;}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You can use increment.
  2. there is no need to check arr[i]==0 because 0%2 == 0



}



return count;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
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) {
return new String[]{"", "", ""};
String []array=new String[3];

String scheme =("[a-z]*(?=://)");
Pattern p1 = Pattern.compile(scheme);
Matcher m1 = p1.matcher(URL);
if(m1.find()){array[0]=m1.group();}

return array;
}
}