Skip to content

Instantly share code, notes, and snippets.

@mamiwinsfall93
Created January 17, 2020 13:13
Show Gist options
  • Save mamiwinsfall93/f5b6dc2f670cb153a743c4b1a6240f11 to your computer and use it in GitHub Desktop.
Save mamiwinsfall93/f5b6dc2f670cb153a743c4b1a6240f11 to your computer and use it in GitHub Desktop.
Sum of the digits of a three-digit number
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