Find the Lambda evens for giving string

This commit is contained in:
YuCheng Hu 2020-07-24 16:02:30 -04:00
parent d34c492adb
commit b4d068c639

View File

@ -14,36 +14,36 @@ import java.util.List;
*/ */
public class LambdaEvensTest { public class LambdaEvensTest {
private final static Logger logger = LoggerFactory.getLogger(LambdaEvensTest.class); private final static Logger logger = LoggerFactory.getLogger(LambdaEvensTest.class);
/** /**
* Lambda Function * Lambda Function
*/ */
interface Arithmetic { interface Arithmetic {
Long operation(Long a, Long b); Long operation(Long a, Long b);
} }
/** /**
* https://www.cwiki.us/display/ITCLASSIFICATION/Build+Castles * https://www.cwiki.us/display/ITCLASSIFICATION/Lambda+Evens
*/ */
@Test @Test
public void testLambdaEvents() { public void testLambdaEvents() {
String line = "1 2 3 4 5 6 "; String line = "1 2 3 4 5 6 ";
String[] lineArray = line.split(" "); String[] lineArray = line.split(" ");
List<Long> numbers = new ArrayList<>(); List<Long> numbers = new ArrayList<>();
Arithmetic division = (Long a, Long b) -> (a % b); Arithmetic division = (Long a, Long b) -> (a % b);
for (String lineChar : lineArray) { for (String lineChar : lineArray) {
if (division.operation(Long.parseLong(lineChar), 2L) == 0) { if (division.operation(Long.parseLong(lineChar), 2L) == 0) {
System.out.print(lineChar + " "); System.out.print(lineChar + " ");
// logger.debug(lineChar + " "); // logger.debug(lineChar + " ");
} }
} }
} }
} }