Solved

java equivalent of cout.setwidth();

Posted on 2007-03-21
7
1,159 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 200 total points
ID: 18767232
System.out.printf("%5s\n", yourString);
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 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