-
Notifications
You must be signed in to change notification settings - Fork 9
HomeWork2:Tasks(1-3,5-7) #8
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
bec2126
db5294d
757d255
0104804
db13136
cee03c3
a74e1a2
36252c6
c5177a5
0e6450d
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package school.lemon.changerequest.java.introduction.hw2; | ||
|
||
public class Task1 { | ||
public static String makeTags(String tag, String text) { | ||
return ""; | ||
public static String makeTags(String tag, String text) | ||
{ | ||
return "<"+tag+">"+text+"</"+tag+">"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,14 @@ | |
|
||
public class Task2 { | ||
public static String firstTwo(String s) { | ||
return ""; | ||
if (s == null) | ||
return null; | ||
else if (s.equals("")) | ||
return ""; | ||
else | ||
if (s.length() <= 2) { | ||
return s.substring(0); | ||
|
||
} | ||
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. If |
||
return s.substring(0, 2); | ||
} | ||
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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. if 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'
}
} |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,17 @@ | |
|
||
|
||
public class Task3 { | ||
public static String comboString(String s1, String s2) { | ||
return ""; | ||
public static String comboString(String s1, String s2) | ||
{ | ||
if(s1 == null) | ||
return s1+s2+s1; | ||
else | ||
if(s2 == null) | ||
return s2 + s1 + s2; | ||
else | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. It's OK, but format your code before submitting. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,14 @@ | |
|
||
public class Task7 { | ||
public static int countEvens(int[] arr) { | ||
return 0; | ||
int count=0; | ||
if(arr == null) | ||
return 0; | ||
for (int anArr : arr) { | ||
if (anArr % 2 == 0) | ||
|
||
count++; | ||
|
||
} | ||
return count; | ||
} | ||
} |
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.