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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.