One thing to note to start with: the final value will not be exactly 70.3, as that can't be exactly represented in a double. If exact decimal values are important to you, you should consider using BigDecimal instead.
It sounds like you want a NumberFormat which omits trailing insignificant digits:
import java.text.*;
public class Test {
public static void main(String[] args) {
// Consider specifying the locale here too
NumberFormat nf = new DecimalFormat("0.#");
double[] speeds = { 50, 80, 120, 70.3 };
for (double speed : speeds) {
System.out.println(nf.format(speed));
}
}
}
(As an aside, I would strongly advise you to keep the [] for array declarations with the type information - double[] speeds instead of double speeds[]. It's much more idiomatic Java, and it puts all the type information in one place.)