|
Author |
Topic: *vanished* question on parsing ints and floats (Read 276 times) |
|
Martin
|
*vanished* question on parsing ints and floats
« on: Mar 14th, 2003, 12:11pm » |
|
hmm... the topic suddenly vanished. anyway, here's the answer Code:float f; int i = 0; String s = "hello 1 2 3 4 5 5.5"; String[] ss = s.split(" "); for(int j = 1; j < ss.length-1; j++) { i += Integer.parseInt(ss[j]); if(j < ss.length-2){ print(ss[j]+" + "); } else { print(ss[j]); } } println(" = "+i+"// Integers"); f = i + Float.parseFloat(ss[ss.length-1]); println(f+"// Integer sum plus 5.5 (Float)"); |
|
|
|
|
|
|