Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int N = 456778889;
- double expo = Math.log10(N);
- int expNum = (int)Math.floor(expo)+1; //gets the total digits in the Integer N
- StringBuilder sb = new StringBuilder("1");
- sb.setLength(expNum);
- 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
- int mostSigNum = N/(Integer.valueOf(f));
- System.out.println(mostSigNum);
- int maxi = (int)(N/Math.pow(10, Math.floor(Math.log10(N))));
- int maxi = Character.digit(String.valueOf(N).charAt(0), 10);
- int N = 456778889;
- double expo = Math.log10(N);
- int expNum = (int)Math.floor(expo);
- String c = IntStream.range(0,expNum).mapToObj(e->"0").collect(Collectors.joining(""));
- String t = "1".concat(c);
- int maxi = N/Integer.parseInt(t);
- System.out.println(maxi);
- public int maxi(int n) {
- return String.valueOf(n)
- .chars()
- .map(i -> i - '0')
- .max()
- .orElse(0);
- }
- @Test
- public void testMaxi() {
- assertEquals(1, maxi(1000));
- assertEquals(7, maxi(7654));
- assertEquals(9, maxi(456778889));
- }
- int number = 456778889;
- int result = IntStream.iterate(number, i -> i / 10) // divide by 10
- .filter(i -> i < 10) // filter out if multiple digits
- .findFirst().getAsInt(); // get the first value
- int number = 456778889;
- int result;
- for (result = number; result >= 10; result /= 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement