aspose file tools*
The moose likes Beginning Java and the fly likes Searching an array - output problems - Please help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Searching an array - output problems - Please help!!" Watch "Searching an array - output problems - Please help!!" New topic
Author

Searching an array - output problems - Please help!!

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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

Joined: Nov 06, 2005
Posts: 93
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

Joined: Nov 06, 2005
Posts: 93
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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching an array - output problems - Please help!!
 
Similar Threads
Problem saving data to text file correctly
Problem when reading a CSVs file as separate words - any help!!
Error passing values to a method - any help!!
Array output continuous in output window and won't terminate - Any help!!
Errors when reading and writing from a text file - any help!!