Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. String x = (JOptionPane.showInputDialog(". Each patamater should be separated with a ',' and without spaces. (eg. 1,2,3)") + ",");
  2. int w = 0, a = 0, y = -1;
  3. for(int i = 0; i < x.length(); i++)
  4. {
  5. if(x.charAt(i) == ',')
  6. {
  7. w++;
  8. }
  9. }
  10. Double[] z = new Double[w];
  11. for(int i = 0; i < x.length(); i++)
  12. {
  13. if(x.charAt(i) == ',')
  14. {
  15. z[a] = Double.parseDouble(x.substring((y + 1), i));
  16. y = i;
  17. a++;
  18. }
  19. }
  20.  
  21. String x = (JOptionPane.showInputDialog(". Each patamater should be separated with a ',' and without spaces. (eg. 1,2,3)") + ",");
  22. String[] split = x.split(",");
  23. Double[] z = new Double[split.length];
  24. int i = 0;
  25. for (String s : split) {
  26. if(s.trim().isEmpty()){
  27. continue;
  28. }
  29. try {
  30. z[i++] = Double.valueOf(s.trim());
  31. } catch (NumberFormatException e) {
  32. e.printStackTrace();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement