Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java labs: How to format the output?

OTG-467455Nov 20 2017 — edited Nov 21 2017

The java labs we have completed consisted of hacking the code to produce the desired output.

I am interested in tidying up the output to do the following:

  1. Strings and value in two separate columns
  2. values printing the "0.00" format
This post has been answered by mNem on Nov 20 2017
Jump to Answer

Comments

NickR2600-Oracle

Sounds like you might be interested in Java Regular Expressions (regex) and pattern matching.  I've found regular expressions useful for formatting and searching Strings and numbers. There is a tutorial from Oracle (https://docs.oracle.com/javase/tutorial/essential/regex/ ).  I've also had luck googling for regular expression examples, since there's so many tricks, options, characters to keep track of.

mNem
Answer

I am using something like the one below. I don't know if that is going to help in

I am interested in tidying up the output to do the following:

  1. Strings and value in two separate columns (???)

 

public void printDetails() {

      System.out.println(String.format("Account Owner: %s", accountOwner));

      System.out.println(String.format("Account Type: %s", accountType));

      DecimalFormat df = new DecimalFormat("$ #,##0.00");

      String formattedBal = df.format(balance);

      System.out.println(String.format("Balance for customer [%s]:  %s", accountOwner, formattedBal));

}

Marked as Answer by OTG-467455 · Sep 27 2020
1 - 2

Post Details

Added on Nov 20 2017
2 comments
178 views