Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. int N = 456778889;
  2. double expo = Math.log10(N);
  3. int expNum = (int)Math.floor(expo)+1; //gets the total digits in the Integer N
  4.  
  5. StringBuilder sb = new StringBuilder("1");
  6. sb.setLength(expNum);
  7. String f = sb.toString().replaceAll("[^0-9]","0"); // It makes the 1 followed by X amount of zero that i require to get my MSB
  8. int mostSigNum = N/(Integer.valueOf(f));
  9. System.out.println(mostSigNum);
  10.  
  11. int maxi = (int)(N/Math.pow(10, Math.floor(Math.log10(N))));
  12.  
  13. int maxi = Character.digit(String.valueOf(N).charAt(0), 10);
  14.  
  15. int N = 456778889;
  16. double expo = Math.log10(N);
  17. int expNum = (int)Math.floor(expo);
  18.  
  19. String c = IntStream.range(0,expNum).mapToObj(e->"0").collect(Collectors.joining(""));
  20. String t = "1".concat(c);
  21. int maxi = N/Integer.parseInt(t);
  22. System.out.println(maxi);
  23.  
  24. public int maxi(int n) {
  25. return String.valueOf(n)
  26. .chars()
  27. .map(i -> i - '0')
  28. .max()
  29. .orElse(0);
  30. }
  31.  
  32. @Test
  33. public void testMaxi() {
  34. assertEquals(1, maxi(1000));
  35. assertEquals(7, maxi(7654));
  36. assertEquals(9, maxi(456778889));
  37. }
  38.  
  39. int number = 456778889;
  40. int result = IntStream.iterate(number, i -> i / 10) // divide by 10
  41. .filter(i -> i < 10) // filter out if multiple digits
  42. .findFirst().getAsInt(); // get the first value
  43.  
  44. int number = 456778889;
  45. int result;
  46. for (result = number; result >= 10; result /= 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement