-3

Essentially my System.out.printf statement is too long. Rather then cutting some of it off and adding another printf statement is there any way to get it to go to the next line without causing a compile error. My code is as follows

System.out.printf("%3d%9s%3d%5s%3d%4s", array[i],"ounces =", pounds, "lbs,", remainder, "oz.);

I tried doing something like

    System.out.printf("%3d%9s%3d%5s%3d%4s", array[i],"ounces =", 
      + pounds, "lbs,", remainder, "oz.);

but that did not work. Any help would be greatly appreciated!

Dylan Kelemen
  • 173
  • 2
  • 9
  • You have misunderstood the purpose of the `+` operator. It is not a general line continuation token. Remove it from your code and it will compile. (Any whitespace characters, including newlines, may separate method arguments.) – VGR Nov 01 '16 at 18:35
  • Just write it on the next line?? The plus operator does not belong there. – QBrute Nov 01 '16 at 18:36
  • 1
    The issue I was having is that my "oz. was not fully enclosed in double quotes. – Dylan Kelemen Nov 01 '16 at 19:07

2 Answers2

2
System.out.printf("%3d%9s%3d%5s%3d%4s",
 array[i],"ounces =",
 pounds, "lbs,",
 remainder, "oz");

what problems?

NetL
  • 76
  • 5
0

To print to a second Line you can use the \n (newline) in the formatting, at the point you choose to cut the Printing of the first Line. For e.g the commands

       double test1f=10.10;
       double test2f=20.20;
       //Let us suppose we want to print test1f at
       //the first line and test2f at the second Line. Then we can write
       System.out.printf("%f \n%f",test1f,test2f);

If you want the printf to add a newline to the last output you can use the \n at the end of formatting in a way like that

        System.out.printf("%f......etc.. \n",arg1,...etc..,);

Hope these might help.

SteveTheGrk
  • 352
  • 1
  • 7