From e9a5bd4af5e3183c5af41446af6ee8e8f65e853d Mon Sep 17 00:00:00 2001 From: Vladymyr Vynnyk Date: Fri, 25 Nov 2016 00:04:54 +0200 Subject: [PATCH] 1-8,10 --- .../changerequest/java/introduction/hw2/Task1.java | 4 +++- .../java/introduction/hw2/Task10.java | 7 ++++++- .../changerequest/java/introduction/hw2/Task2.java | 4 +++- .../changerequest/java/introduction/hw2/Task3.java | 9 +++++++-- .../changerequest/java/introduction/hw2/Task4.java | 7 ++++++- .../changerequest/java/introduction/hw2/Task5.java | 4 ++++ .../changerequest/java/introduction/hw2/Task6.java | 9 ++++++++- .../changerequest/java/introduction/hw2/Task7.java | 14 +++++++++++++- .../changerequest/java/introduction/hw2/Task9.java | 13 ++++++++++++- 9 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java index fb8a529..38bda8e 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task1.java @@ -2,6 +2,8 @@ public class Task1 { public static String makeTags(String tag, String text) { - return ""; + + + return "<"+tag+">"+text+""; } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java index 95ec7eb..5440e0b 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task10.java @@ -2,6 +2,11 @@ public class Task10 { public static String trim(String text) { - return ""; + + if(text==null){return null;} + String resultString = text.trim(); + + + return resultString; } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java index fd4494e..3dae50f 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task2.java @@ -3,6 +3,8 @@ public class Task2 { public static String firstTwo(String s) { - return ""; + if(s.length()<=2){return s;} + else return s.substring(0,2); + } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java index 4d2e987..c57c230 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task3.java @@ -3,6 +3,11 @@ public class Task3 { public static String comboString(String s1, String s2) { - return ""; - } +if(s1==null){s1="null";} + if(s2==null){s2="null";} + if(s1.length()>=s2.length()){ + return s2+s1+s2;} + else return s1+s2+s1; + + } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java index 35edd98..d2a5d5e 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task4.java @@ -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;} + 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); } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java index 5e42b95..72e55e5 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task5.java @@ -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]) { + +return true; } + return false; } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java index ee19236..72b76fb 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task6.java @@ -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; } } diff --git a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java index f95de42..4f92456 100644 --- a/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java +++ b/src/main/java/school/lemon/changerequest/java/introduction/hw2/Task7.java @@ -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