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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. float floatValue = 12.34567f;
  13. String str= String.format("%.4f", floatValue);
  14. // remove the dot or minus
  15. str = str.replaceAll("[-|.]", "");
  16. int [] nums = new int[str.length()];
  17. for (int i=0; i<str.length(); i++) {
  18. nums [i] = str.charAt(i)-'0';
  19. System.out.println("nums["+ i + "] = " + nums[i]);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.05s 320576KB
stdin
Standard input is empty
stdout
nums[0] = 1
nums[1] = 2
nums[2] = 3
nums[3] = 4
nums[4] = 5
nums[5] = 7