Skip to content

Commit 3071f28

Browse files
authored
Merge pull request kelvins#307 from SGSTAR01/main
Translated Comments, Methods,Variables of AddTwoNumbers.java
2 parents 9c9cce3 + 438eb8a commit 3071f28

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

src/java/AddTwoNumbers.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,53 @@
22
import java.util.ArrayList;
33
import java.util.List;
44

5-
// Utilizado o OpenJDK 17.0.3
5+
// Utilized OpenJDK 17.0.3
66
/*
77
* @author Gabriel Nascimento. GitHub: Gabrielxdf
88
*
99
*/
10-
public class SomaDoisNumeros {
10+
public class AddTwoNumbers {
1111
/**
12-
* Para cada elemento da lista de valores, o método percorre o restante da lista verificando se há
13-
* algum número cuja some de ambos seja o valor esperado.
12+
* This program takes a list of numbers and checks if there are two numbers whose sum is equal to
13+
* the expected value.
1414
*
15-
* @param valores Lista de valores que será verificada.
16-
* @param esperado Valor esperado pela soma de dois números da lista valores.
15+
* <p>For each element in the list of values, this method goes through the list, checking if there
16+
* is any number whose sum of both is the expected value.
17+
*
18+
* @param values List of values that will be checked.
19+
* @param expected Expected value from the sum of two numbers from the values list.
1720
*/
18-
public static void verificaSeExisteSoma(List<Integer> valores, int esperado) {
19-
boolean resultado = false;
20-
for (int i = 0; i < valores.size() - 1; i++) {
21-
for (int j = i + 1; j < valores.size(); j++) {
22-
if (valores.get(i) + valores.get(j) == esperado) {
23-
resultado = true;
21+
public static void checkIfThereSumExists(List<Integer> values, int expected) {
22+
boolean result = false;
23+
for (int i = 0; i < values.size() - 1; i++) {
24+
for (int j = i + 1; j < values.size(); j++) {
25+
if (values.get(i) + values.get(j) == expected) {
26+
result = true;
2427
System.out.println(
2528
MessageFormat.format(
26-
"Verdadeiro - {0} + {1} = {2}", valores.get(i), valores.get(j), esperado));
29+
"True - {0} + {1} = {2}", values.get(i), values.get(j), expected));
2730
break;
2831
}
2932
}
30-
if (resultado) {
33+
if (result) {
3134
break;
3235
}
3336
}
34-
if (!resultado) {
37+
if (!result) {
3538
System.out.println(
36-
MessageFormat.format("Falso - Não há dois números cuja soma seja {0}", esperado));
39+
MessageFormat.format("False - There are no two numbers whose sum is {0}", expected));
3740
}
3841
}
3942

4043
public static void main(String[] args) {
41-
List<Integer> valores = new ArrayList<Integer>(List.of(12, 33, 5, 9, 54, 100));
42-
System.out.println("------Deve ser verdadeiro------");
43-
verificaSeExisteSoma(valores, 133);
44-
verificaSeExisteSoma(valores, 42);
45-
verificaSeExisteSoma(valores, 66);
46-
System.out.println("------Deve ser falso------");
47-
verificaSeExisteSoma(valores, 13);
48-
verificaSeExisteSoma(valores, 100);
49-
verificaSeExisteSoma(valores, 60);
44+
List<Integer> values = new ArrayList<Integer>(List.of(12, 33, 5, 9, 54, 100));
45+
System.out.println("------It must be true------");
46+
checkIfThereSumExists(values, 133);
47+
checkIfThereSumExists(values, 42);
48+
checkIfThereSumExists(values, 66);
49+
System.out.println("------It must be false------");
50+
checkIfThereSumExists(values, 13);
51+
checkIfThereSumExists(values, 100);
52+
checkIfThereSumExists(values, 60);
5053
}
5154
}

0 commit comments

Comments
 (0)