Advertisement
ASDEVELOPMENT

Java - Drugi zadatak

Mar 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. package testiranjeZira;
  2.  
  3.  
  4. import java.util.*;
  5.  
  6.  
  7.  
  8. public class zadaciUPR{
  9.    
  10.    
  11.    
  12.    
  13.    
  14.    
  15.     public static void main(String args[]){
  16.        
  17.        
  18.        
  19.         Scanner input = new Scanner(System.in);
  20.        
  21.         // Napisati program kojim ćemo sabrati cifre broja 12345
  22.        
  23.        
  24.         int broj;
  25.         int sumaCifara = 0;
  26.        
  27.        
  28.         System.out.println("Unesite broj: ");
  29.        
  30.         broj = input.nextInt();
  31.        
  32.        
  33.         int cifra = 0;
  34.        
  35.         while(broj != 0){
  36.            
  37.             cifra = broj%10; // izvdavajamo broj sa najmanjoj težinom
  38.            
  39.             sumaCifara = sumaCifara + cifra;
  40.            
  41.             broj = broj/10; // odbacujemo cifru sa najmanjom težinom
  42.            
  43.         }
  44.        
  45.        
  46.         System.out.println("Suma cifara za broj iznosi: " + sumaCifara);
  47.        
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement