Solved

java equivalent of cout.setwidth();

Posted on 2007-03-21
7
1,134 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now