Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1.     public static int najveca(int n) {
  2.         int max = 0;
  3.         while (n > 0) {
  4.             if (max < n % 10)
  5.                 max = n % 10;
  6.             n /= 10;
  7.         }
  8.  
  9.         return max;
  10.     }
  11.  
  12.     public static int novi(int n) {
  13.         int t = 0;
  14.         int max = najveca(n);
  15.         int izbacenih = 0;
  16.         int stepen = 1;
  17.        
  18.         while(n > 0) {
  19.             int digit = n % 10;
  20.             n /= 10;
  21.  
  22.             if (digit == max) {
  23.                 if (izbacenih == 0) {
  24.                     izbacenih++;
  25.                 } else {
  26.                     t = digit * stepen + t;
  27.                     stepen *= 10;
  28.                 }
  29.             } else  {
  30.                 t = digit * stepen + t;
  31.                 stepen *= 10;
  32.             }
  33.         }
  34.         return t;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement