What is the C++ equivalent syntax in Java - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


What is the C++ equivalent syntax in Java

weitechweitech Posts: 6Member


  • arb123arb123 Posts: 696Member
    : cout.setf(ios::left);
    : cout.setf(ios::adjustfield);

    Java provides alot of powerful message formatting utilities which are not tied to I/O streams. These provide all sorts of mechanisms to allow you to format messages according to the local language and country-specific conventions. Check out the Javadoc and Sun's tutorials.

    import java.text.DecimalFormat;
    import java.text.MessageFormat;
    import java.text.NumberFormat;
    import java.util.Date;

    public class FormatOutput {

    public static void main(String[] args) {
    double earnings = 126389471024.78826538;
    double years = 12.3;
    Date now = new Date();
    String name = "John";

    NumberFormat numberFormatter = new DecimalFormat("###,###.##");

    String formattedNumber = numberFormatter.format(earnings);

    Object[] arguments = { name, formattedNumber, new Double(years), now, };
    String message =
    "{0} earned ${1} after {2,number,integer} years as of {3,date}";

    String outputString = MessageFormat.format(message, arguments);

    (not that the above is best practice)

    [size=1](Its just my sig)
    HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

Sign In or Register to comment.