Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9433864

Browse filesBrowse files
feat: add exercício dia 4
1 parent 53826e4 commit 9433864
Copy full SHA for 9433864

File tree

2 files changed

+45
-1
lines changed
Filter options

2 files changed

+45
-1
lines changed

‎src/Main.java

Copy file name to clipboardExpand all lines: src/Main.java
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import dayFour.WhoLikesIt;
12
import dayOne.contagemBits.detectarPangram.Exercicio;
23
import dayThree.SplitStrings;
34
import dayTwo.CoutingSheep;
45
import dayTwo.EvenOrOdd;
56

7+
import java.util.ArrayList;
68
import java.util.Arrays;
79

810
public class Main {
@@ -14,8 +16,15 @@ public static void main(String[] args) {
1416
// Boolean[] sheeps = {true, false, true, false, true, false, true, false, false, false, false, true, true};
1517
// CoutingSheep coutingSheep = new CoutingSheep(sheeps);
1618
// System.out.println(coutingSheep.countSheeps());
17-
System.out.println(Arrays.toString(SplitStrings.solution("abcdef")));
19+
// System.out.println(Arrays.toString(SplitStrings.solution("abcdef")));
1820
// SplitStrings.solution("abcdef");
1921
// SplitStrings.solution("abc");
22+
String noNames[] = new String[0];
23+
String twoNames[] = {"Alex", "Jacob"};
24+
String threeNames[] = {"Alex", "Jacob", "Mark"};
25+
String fourNames[] = {"Alex", "Jacob", "Mark", "Max"};
26+
27+
// System.out.println(WhoLikesIt.whoLikesIt(noNames));
28+
System.out.println(WhoLikesIt.whoLikesIt(twoNames));
2029
}
2130
}

‎src/dayFour/WhoLikesIt.java

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dayFour;
2+
3+
/**
4+
* Você provavelmente conhece o sistema "curtir" do Facebook e outras páginas. As pessoas podem "curtir" posts de blog, fotos ou outros itens.
5+
* Queremos criar o texto que deve ser exibido ao lado de tal item.
6+
* Implemente a função que recebe um array contendo os nomes das pessoas que gostam de um item. Ela deve retornar o texto de exibição conforme mostrado nos exemplos:
7+
* [] --> "no one likes this"
8+
* ["Peter"] --> "Peter likes this"
9+
* ["Jacob", "Alex"] --> "Jacob and Alex like this"
10+
* ["Max", "John", "Mark"] --> "Max, John and Mark like this"
11+
* ["Alex", "Jacob", "Mark", "Max"] --> "Alex, Jacob and 2 others like this"
12+
* Observação: para 4 ou mais nomes, o número "and 2 others"simplesmente aumenta.
13+
*/
14+
public class WhoLikesIt {
15+
16+
public static String whoLikesIt(String... names) {
17+
String text = "no one likes this";
18+
19+
if(names.length != 0){
20+
if(names.length >= 4){
21+
int others = names.length - 2;
22+
text = names[0] + ", " + names[1] + " and" + others + "others like this";
23+
} else if (names.length % 2 == 0) {
24+
text = names[0] + " and " + names[1] + " like this";
25+
} else if(names.length % 2 != 0 && names.length > 1){
26+
text = names[0] + ", " + names[1] + " and " + names[2] + " like this";
27+
} else {
28+
text = names[0] + " likes this";
29+
}
30+
return text;
31+
}else {
32+
return text;
33+
}
34+
}
35+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.