| This is a C statement :- printf("%10.2f",x); The same thing can be done in a more understandable way in c++ :- cout << setw(10) << setprecision(2) << showpoint << x; But doing that in Java is neither short nor simple :- java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance(); formatter.setMinimumFractionDigits(2); formatter.setMaximumFractionDigits(2); String s = formatter.format(x); for (int i = s.length(); i < 10; i++) System.out.print(' '); System.out.print(s); DO YOU STILL THINK JAVA IS SIMPLER ? |
| C/C++ V/S JAVA |
| To learn C/C++ from Saurabh, mail to :- [email protected] |