Advertisement
MilaDimitrovaa

do-while / Сбор на числа

Nov 18th, 2020
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.30 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class sumirane {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         Scanner scan = new Scanner(System.in);
  8.        
  9.         int n = scan.nextInt();
  10.         int sum = 0;
  11.         do {
  12.             sum = sum + (n % 10);
  13.             n = n / 10;
  14.         }while(n > 0);
  15.    System.out.println("Suma:" + sum);
  16.     }
  17.  
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement