-
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
1-8,10 #5
base: master
Are you sure you want to change the base?
1-8,10 #5
Changes from all commits
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 |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
public class Task10 { | ||
public static String trim(String text) { | ||
return ""; | ||
|
||
if(text==null){return null;} | ||
String resultString = text.trim(); | ||
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 not an option. Task was do it without default trim. |
||
|
||
|
||
return resultString; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
public class Task2 { | ||
public static String firstTwo(String s) { | ||
return ""; | ||
if(s.length()<=2){return s;} | ||
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. Please add null check too. |
||
else return s.substring(0,2); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
|
||
public class Task3 { | ||
public static String comboString(String s1, String s2) { | ||
return ""; | ||
} | ||
if(s1==null){s1="null";} | ||
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. 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 |
---|---|---|
|
@@ -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;} | ||
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. https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#floorMod-int-int- |
||
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 |
---|---|---|
|
@@ -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]) { | ||
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. Please extract to variables |
||
|
||
return true; } | ||
|
||
return false; | ||
} | ||
} |
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;} | ||
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.
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
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; | ||
} | ||
} | ||
|
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 use
String.format()