0

I need to output something that looks like this:

What the output should be

This is what i've tried without the asterisks

    System.out.printf("%-15s %20s %n",name, "Gross: " + grossPay );
    System.out.printf("%20s %n Taxes(25): " + taxes);
    System.out.printf("%20s %n Net: ",netPay);

The grossPay, taxes, netPay are all defined else ware but they and their labels have to be right aligned and I don't know how to go about doing that.

  • [Possible dupe](https://stackoverflow.com/questions/26594810/how-to-print-numbers-in-right-aligned-manner?noredirect=1&lq=1). – user202729 Mar 21 '18 at 13:27
  • You are printing a newline (`%n`) right after `Taxes(25)`. Think about it. (And if you haven’t already, read the [documentation for Formatter](https://docs.oracle.com/javase/9/docs/api/java/util/Formatter.html), which is what System.out.printf uses.). – VGR Mar 21 '18 at 13:59

1 Answers1

0

This works for me:

String taxes = "82.47";
System.out.printf(String.format("**%20s**", String.format("Taxes (25): %s", taxes)));


**   Taxes (25): 82.47**
RBH
  • 261
  • 1
  • 10