Skip to content

Commit 4371d6d

Browse files
committed
Simple Evens
1 parent 131c9b5 commit 4371d6d

File tree

2 files changed

+40
-43
lines changed

2 files changed

+40
-43
lines changed

src/easy/LongestWord.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/easy/SimpleEvens.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package easy;
2+
3+
/**
4+
* Have the function SimpleEvens(num) check whether
5+
* every single number in passed in parameter is even.
6+
* If so, return the string true, otherwise return the string false.
7+
* For example: if num is 4602225 your program should
8+
* return the string false because 5 is not an even number.
9+
*/
10+
public class SimpleEvens {
11+
12+
/**
13+
* Simple Evens function.
14+
*
15+
* @param num input number
16+
* @return "true" if a number is even
17+
*/
18+
private static String simpleEvens(Integer num) {
19+
String[] digits = num.toString().split("");
20+
for (String digit : digits) {
21+
if (Integer.parseInt(digit) % 2 != 0) {
22+
return "false";
23+
}
24+
}
25+
return "true";
26+
}
27+
28+
/**
29+
* Entry point.
30+
*
31+
* @param args command line arguments
32+
*/
33+
public static void main(String[] args) {
34+
String result1 = simpleEvens(222252);
35+
System.out.println(result1);
36+
String result2 = simpleEvens(228);
37+
System.out.println(result2);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy