Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Division_02 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- //спирам да сумирам, когато нямам цифри (число = 0)
- //продължавам => число != 0
- //взимам последната цифра
- //добавям я към сумата
- //премахвам последната цифра
- int sum = 0; //сума на цифрите
- while (number != 0) {
- int lastDigit = number % 10; //последната цифра
- sum += lastDigit;
- number = number / 10; // number /= 10
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment