Advertisement
Flaron

Udemy_17.EvenDigitSum

Sep 14th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. package lista.Alapok;
  2.  
  3. public class Main {
  4.  
  5. public static int getEvenDigitSum(int number) {
  6. int count, last;
  7. if (number<0) return -1;
  8.  
  9. else {
  10. count=0;
  11. last=0;
  12. while (number>0){
  13. if (number%2==0){
  14. last=number%10;
  15. count+=last;
  16. }
  17. number /= 10;
  18. }
  19. } return count;
  20. }
  21.  
  22.  
  23. public static void main(String[] args) {
  24. System.out.println(getEvenDigitSum(2114122));
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement