public class Solution {
public static void main(String[] args) {
System.out.println(sumDigitsInNumber(546));
}
public static int sumDigitsInNumber(int number) {
int sum;
int tempNum = number / 10 * 10;
int firstDigit = number - tempNum;
int secondDigit = tempNum/100;
int thirdDigit = secondDigit -1;
sum = firstDigit + secondDigit + thirdDigit;
return sum;
}
}
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) {
int sum;
int tempNum = number / 10 * 10;
int firstDigit = number - tempNum;
int secondDigit = tempNum/100;
int thirdDigit = secondDigit -1;
sum = firstDigit + secondDigit + thirdDigit;
return sum;
}
}