Solved

java equivalent of cout.setwidth();

Posted on 2007-03-21
7
1,152 Views
Last Modified: 2008-02-26
what is the java equivalent of the C++ term:

cout.setwidth(5);
or
cout.setw(5);

I basically need to lineup the columns after 5 empty characters.

Thanks
0
Comment
Question by:Squadless
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767188
Use System.out.printf
0
 
LVL 1

Author Comment

by:Squadless
ID: 18767220
and where do i specify the width? System.out.printf(5)?
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 18767232
System.out.printf("%5s\n", yourString);
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:jkr
ID: 18767244
0
 
LVL 86

Expert Comment

by:jkr
ID: 18767251
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 18767284
It doesn't really have a equivalent.
you have a few options:

1. create a method that pads a string

System.out.println(pad(x, 5)+pad(y, 5)+pad(z, 5));

2. System.out.printf("%5d%5d%5d\n", x, y, z);

3. Use MessageFormat

Let me know if u have any questions
0
 
LVL 1

Author Comment

by:Squadless
ID: 18767296
you again!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question