• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print all Numbers of Array in java?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

This is my code



and i am getting this output

----------
! 1712 !2156|
----------
! 1713 !4583|
----------
! 1714 !3981|
----------

[HENRY: 6000+ LINES DELETED -- Isn't it a bit ridiculous hard to read when you flood a post with thousands of output lines?]

----------
! 4998 !3094|
----------
! 4999 !836|
----------
12:10:56



I am expecting Number to be print from Index ) but they are not printing ,why?

If I use arraysize like 2000 I am getting all number starting from 0 to 1999

why?

Thanks
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are printing but output is too large therefore it override previous output and start displaying from 1712 !2156|
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply

I am using Eclipse



Which tool or Ide I should use to view all numbers?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:
Which tool or Ide I should use to view all numbers?


Isn't it easier to just redirect standard output to a file? Practically all command windows (or tool output windows) will truncate -- or it can theoretically run out of memory holding all that history.

Henry
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is simply a formatting problem. Find out how to format your output with the % tags. You can find out about that in the Formatter class and in several places in the Java Tutorials: 1 2 3. No 3 is about formatting classes like DecimalFormat, so use no 1 + 2.
Also avoid multiple print instructions. If you can join the three instructions in lines 34‑36 into one instruction you can probably improve performance. Maybe only by a few milliseconds, but in 5000 lines that makes several seconds.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:If I use arraysize like 2000 I am getting all number starting from 0 to 1999
why?

Erm...because that's what you've coded?

Arrays have a fixed size - which you appear to have redundantly assigned to arraySize - and a generic "print" method can't possibly know what portion of that array contains the things you want to display unless you tell it.

A List, on the other hand, contains only as many elements as you've supplied to it, so it will only print out that many.

So maybe the answer is to use a List, rather than an array.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!