Solved

java equivalent of cout.setwidth();

Posted on 2007-03-21
7
1,138 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Least Squares Curve Fitting 4 61
looking for unix program to search some keywords in side EAR WAR and JAR files 10 81
print map entry 34 55
max float value 3 26
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

895 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

16 Experts available now in Live!

Get 1:1 Help Now