Created
January 17, 2020 13:13
-
-
Save mamiwinsfall93/f5b6dc2f670cb153a743c4b1a6240f11 to your computer and use it in GitHub Desktop.
Sum of the digits of a three-digit number
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
package com.codegym.task.task01.task0132; | |
/* | |
Sum of the digits of a three-digit number | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
System.out.println(sumDigitsInNumber(546)); | |
} | |
public static int sumDigitsInNumber(int number) { | |
double sum1 = number%100;//46 | |
double sum2 = sum1/10;// 4.6 | |
double sum3 = number%10; //6 | |
double sum4 = number /100; //5.48 | |
return (int) (sum4+ sum2 + sum3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment