Skip to content

Instantly share code, notes, and snippets.

@drguildo
Created January 19, 2019 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drguildo/c648d6d0c8f74dde3bae5ae582e442bb to your computer and use it in GitHub Desktop.
Save drguildo/c648d6d0c8f74dde3bae5ae582e442bb to your computer and use it in GitHub Desktop.
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