Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Array printing format

 
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to print an array with each element spaced a certain distance horizontally like this.

E1 E2 E3 E4

I know how to print an array, but it only prints them out one at a time skipping a line each time.
E1
E2
E3
E4

This is my code for printing my array



how can I print this the way I want?


 
author
Posts: 23867
141
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, if you use print() instead of println() then that won't print the newline ... then all you have to do is to print the spaces between the elements.

Henry
 
Kev Woo
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
haha that would help...

thanks.

also, is there a better way to set the number of spaces between other then adding a + " "); at the end?
 
Marshal
Posts: 68014
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the printf() methods. If the link doesn't supply enough information, be sure to ask again.
 
Campbell Ritchie
Marshal
Posts: 68014
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peachy Manasis,
Your post was moved to a new topic.
 
Campbell Ritchie
Marshal
Posts: 68014
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I earlier wrote:Peachy Manasis,
Your post was moved to a new topic.

You have asked a new question on a current thread. That may deprive Kev Woo of an answer to his original question. Please avoid such thread hi-jacking.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!