• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Searching an array - output problems - Please help!!

 
celine scarlett
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm still plugging away with all these arrays and so forth, but I'm mow trying to search through an array. The array is sorted using a Bubble Sort Algorithm, and I've written a main class to test the searching capabilities.

The problem is that the output, when I run the main class, is simply freezing and not giving any data. It does not even request a number to input.

A bit perplexed at the moment!

Anyway, my code is as follows,



It's probably something really simple, but I just can't see it at the moment.

Any help really appreciated!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to call

System.out.flush()

right after your print() call. If you call print(), the output won't necessarily appear on the screen until you either call println(), or flush(). I say "won't necessarily" because if you use print() to print a lot of data, then the buffer may flush automatically.
 
celine scarlett
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I've tried adding 'System.out.flush();' to the code, but the output is still the same. It simple stalls and freezes at 'run-single:' in the output window.

Anybody got any ideas why?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps your bubble sort routine (not shown here) never returns. Have you tested that already, apart from this searching routine? In particular, have you tested that it can sort this particular data file correctly?
 
celine scarlett
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. Yes, the sort algorithm works fine. I've tested it on this file, and a couple of others. I just can't seem to see why this test main class doesn't work.

A bit strange.

Here's the code for the complete BubbleSort class:



Any help really appreciated!!
 
celine scarlett
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I cannot believe how simple the answer actually was in the end.

Within the tester main class, all I had to do was add 'ln' to 'System.out.print'.

It now works perfectly.

Thanks for all the help!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic