?
Solved

java equivalent of cout.setwidth();

Posted on 2007-03-21
7
Medium Priority
?
1,171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 total points
ID: 18767232
System.out.printf("%5s\n", yourString);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:jkr
ID: 18767251
0
 
LVL 92

Accepted Solution

by:
objects earned 1200 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 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…
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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