fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static double withFloor(int i) {
  11. return i / Math.pow(10, 1 + Math.floor(Math.log10(i)));
  12. }
  13.  
  14. static double withCeil(int i) {
  15. return i / Math.pow(10, Math.ceil(Math.log10(i)));
  16. }
  17.  
  18. static void test(int i) {
  19. System.out.printf("input=%d\twithFloor=%s\twithCeil=%s%n", i, withFloor(i), withCeil(i));
  20. }
  21.  
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. test(1);
  25. test(2);
  26. test(9);
  27. test(10);
  28. test(11);
  29. test(19);
  30. test(23);
  31. test(100);
  32. test(999);
  33. }
  34. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
input=1	withFloor=0.1	withCeil=1.0
input=2	withFloor=0.2	withCeil=0.2
input=9	withFloor=0.9	withCeil=0.9
input=10	withFloor=0.1	withCeil=1.0
input=11	withFloor=0.11	withCeil=0.11
input=19	withFloor=0.19	withCeil=0.19
input=23	withFloor=0.23	withCeil=0.23
input=100	withFloor=0.1	withCeil=1.0
input=999	withFloor=0.999	withCeil=0.999