Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. static int BrojDjeljivSaSumomCifara(int broj1) {
  8. int cifre;int suma=0; int broj=broj1;int broj2=broj1;
  9. while(broj>0){
  10. cifre=broj%10;
  11. suma+=cifre;
  12. broj=broj/10;
  13.  
  14. }
  15.  
  16. if(broj2%suma==0)
  17. return 1; else return 0;
  18.  
  19. }
  20.  
  21.  
  22. public static void main(String[] args) {
  23.  
  24.  
  25.  
  26. System.out.println("Unesite n");
  27. Scanner ulaz= new Scanner(System.in);
  28. int n=ulaz.nextInt();
  29. //System.out.println("n je ",n);
  30.  
  31. int[] djeljivi=new int[n];
  32. int t=0;
  33.  
  34.  
  35. for(int i=1;i<n;i++){
  36. if(BrojDjeljivSaSumomCifara(i)!=0) {djeljivi[t]=i;t++;}
  37.  
  38. }
  39.  
  40. System.out.println("Brojevi koji su djeljiv sa sumom svojih cifara su ");
  41. for(int g=0;g<t;g++){
  42. System.out.print(djeljivi[g]);
  43. }
  44.  
  45. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement