Created
January 19, 2019 14:20
-
-
Save drguildo/c648d6d0c8f74dde3bae5ae582e442bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
class Main { | |
static public int EvenOddDigitsSum(int input1, String input2) { | |
int sum = 0, temp, num = 0; | |
if (input2 == "even") { | |
temp = input1; | |
while (temp != 0) { | |
System.out.println("Checking " + temp); | |
num = temp % 10; | |
if (temp % 2 == 0) { | |
sum += num; | |
} | |
temp = temp / 10; | |
} | |
} else if (input2 == "odd") { | |
temp = input1; | |
while (temp != 0) { | |
System.out.println("Checking " + temp); | |
num = temp % 10; | |
if (temp % 2 != 0) { | |
sum += num; | |
} | |
temp = temp / 10; | |
} | |
} | |
return sum; | |
} | |
public static void main(String args[]) { | |
System.out.println(EvenOddDigitsSum(1234567890, "even")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment