• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Searching an array - output problems - Please help!!

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic