server_crash 64 Postaholic

You never increment low so it's always the same which causes the infinite loop.

server_crash 64 Postaholic

I have written a binary search algorithm in java. I have a statement that when the search key is found it is printed to a terminal window. This statement when when called just keeps printing over and over and i cant figure out why :sad: . Can any one help?

import java.util.Random;


public class BinarySearch
{
Random RandomGenerator; // declares the random generator that generates the array
int maxLength; // initialises the varible max lenght
private int[] a; // the array is declared

public BinarySearch()
{
RandomGenerator = new Random(); // create random generator
maxLength = 100; // set the maximum value for max lenght
}

public void BinarySearchFunction(int n)
{
a = new int[n]; // create array
for (int i=0; i<n; i++)
{
a = RandomGenerator.nextInt(maxLength); // new random numbers
}

print(a);

{
int in, out;

for(out=1; out < a.length; out++) // out is dividing line
{
int temp = a[out]; // remove marked item
in = out; // start shifts at out
while(in>0 && a[in-1] >= temp) // until one is smaller,
{
a[in] = a[in-1]; // shift item to right
--in; // go left one position
}
a[in] = temp; // insert marked item


}

print(a); // prints sorted numbers
}
}


public void BinarySearch(int key)
{
int low = 0;
int …

server_crash 64 Postaholic

Without seeing the code that is mentioned in the stacktrace it's impossible to say more, but it sounds like a method is being called with a null argument where that's illegal.

I was wondering about that. I had never heard of a SocketConnectionWriter.

server_crash 64 Postaholic

I'm not too sure about this. It could be a thread timing out, or something blocking it. You'll probably have to wait until someone smarter than me posts.

server_crash 64 Postaholic

Plus, you haven't asked a question. If you did, I might be able to answer it.

server_crash 64 Postaholic

I am learning JavaScript and am lost.

Yes, you are lost. This is a JSP forum, not javascript. ;)

server_crash 64 Postaholic

What do you mean you don't know what node to look at?

server_crash 64 Postaholic

First off, I would suggest adding some tab characters "\t" instead of explicitly adding all the white spaces in. It makes your code really hard to read like it is.

server_crash 64 Postaholic

startsWith(String prefix)
endsWith(String postfix)

server_crash 64 Postaholic

So what's your question? I see nothing but a bunch of code in need of a few band aids, but no question.

server_crash 64 Postaholic

Hitler would be a good one. You could definately get some good/bad scenarios out of him.

server_crash 64 Postaholic

Just felt like saying something.

server_crash 64 Postaholic

[edit]
Bah!
[/edit]

:eek: Abuse Reported.

server_crash 64 Postaholic

Does anyone know of a place(online) that sells cool pc cases that have a lot of brackets for fans? Or a specific model which supports excellent cooling?

server_crash 64 Postaholic

You could use a StringTokenizer to read everything that's a word(doesn't read white space).
Get the length of the word.
In a for loop you can process the char at index 'i' by using charAt(i).

server_crash 64 Postaholic

Take out the break statements if you want all them to execute, but that probably means your logic is flawed.

server_crash 64 Postaholic

In that case you don't need the while loop.
All you need to do is change the default case statement to exit:

switch (currency) //use a switch statement to switch currency
{

case 1:
mygifts.USDollarsEntered();
break;

case 2:
mygifts.EurosEntered();
break;

case 3:
mygifts.YenEntered();
break;

default: // total collected
System.out.print ("Exit and add the total collected.");
System.exit(0);
break;
}

There's no reason for a while loop. The variable currency is never changed in the while loop, so even if you did create a viable exit condition it would still be an infinite loop. So, just get rid of the loop and everything should work.

server_crash 64 Postaholic

Just as I thought; it's an infinite loop. UnitOfCurrency is never set to four. Now, from what I understand you want to loop until the user enters something other than 1,2,3, correct?

Let me know exactly why you are looping and what you expect it to do so we can fix up something that will work.

server_crash 64 Postaholic

Do you mind showing me the loop?

server_crash 64 Postaholic

UnitOfCurrency is never equal to 4. You may be performing some kind of arithmetic that skips four:

you may start out at 3.
Then add two, which is 5. That continues the loop because it's still not four.

server_crash 64 Postaholic

Loop not written properly. [Probably an infinite loop]

for (int i=10; i>=0; i++)
{
}


That would be an example.

server_crash 64 Postaholic

It might be. I was trying to recall from memory, so I wouldn't doubt it if I'm wrong. I'll check it out real fast.

server_crash 64 Postaholic

Get sex

Have you illustrated some of these ideas? It could help.

server_crash 64 Postaholic

I thought it was strspn(parameters); ?

server_crash 64 Postaholic

You could pick about any of the constitution framers.

server_crash 64 Postaholic

J2ME, I would guess.

server_crash 64 Postaholic

Use a file filter. I think there's an accept() method that you can provide a default extension in, but not sure.

server_crash 64 Postaholic

extensions maybe?

Binary is suppose to be .dat
Test is .txt or .text

server_crash 64 Postaholic

I totally don't understand what you're asking for.

server_crash 64 Postaholic

What do you mean from a different context?

To close:

System.exit(0);


To open:

Just create an instance

server_crash 64 Postaholic

Multiple opinions are always good.

server_crash 64 Postaholic

If I remember right, the vector class is very slow when inserting elements to the front, or any place except the back. So, if there is a method push_front() then you probably shouldn't use it.

server_crash 64 Postaholic

Try this for Windows. It writes itself a Batch File and runs it. After the Exe File is deleted, the batch file also deletes itself. A reboot isnt needed here.

#include <iostream>
#include <fstream.h>
#include <windows.h>
#include <shellapi.h>
int main( int argc, char* argv[] ) 
{
	char ExeFileName[ 260 ] = "";
	char BatFileName[ 260 ] = "";
	strncpy( ExeFileName, argv[ 0 ], strlen( argv[ 0 ] ) + 1);
	strncpy( BatFileName, argv[ 0 ], strlen( argv[ 0 ] ) + 1 );
	char* SlashPos = strrchr( BatFileName, '\\' );
	strncpy( SlashPos, "\\BatFileName.bat", strlen("\\BatFileName.bat" )  + 1  );
	ofstream BatFile(BatFileName);
	BatFile << ":Begin" << "\n";
	BatFile << "del " << ExeFileName << "\n";
	BatFile << "if exist " << ExeFileName << " goto Begin" << "\n";
	BatFile << "del " <<  BatFileName << "\n";
	BatFile.close();
	ShellExecute(NULL, "open", BatFileName, NULL, NULL, SW_HIDE);
	return 0;
}

That's pretty clever ;)

server_crash 64 Postaholic

I'd say no, but there's no way to tell. The best thing to do is ask your teacher/professor. You can always do both and that way you won't have to worry.

server_crash 64 Postaholic

If I understand correctly, you can set the visibility:

Component.setVisible(false);

Or even better, set the editability:

Component.setEditable(false);

server_crash 64 Postaholic

I'd say it's platform independant. Most platforms have a lock on files that are in use, and you can't delete them:

#include <cstdlib>
#include <cstdio>

int main(int argc, char * * argv)
{
   remove(argv[0]);
   return EXIT_SUCCESS;

}

If that doesn't work, then as someone already mentioned, then it's got a lock on the file.


Maybe if you could find a renowned virus writer the question could be answered ;)

server_crash 64 Postaholic

I don't think it would make sense to 'link' the classes, or at least the way you have written them it doesn't make sense. From what I can see, you need to make the 'CurrencyConvert' class nothing but methods and possibly aggregate that class into the Gift class. With what you have now, there's really nothing you can do. Not being rude or anything, but it'd probably be best to start over.

I'll give a small example of what it should look like:

public class ConvertCurrency
{
    private final double USdollars_Rate = 1.0
    private final double Euro_Rate = 1.24
    private final double Yen_Rate = .0091

   public ConvertCurrency()
   {
       super();
   }
    
   public void convertToUS(double amount)
   {
         //conversion
   }
}

Second class

class Gift
{
   private ConvertCurrency  cc;
  
   public Gift()
   {
      super();
      cc = new ConvertCurrency();
   }
   public void getAmount()
   {
      System.out.print("Enter an amount --> ");
     //get the input
    cc.convertToUS(input);
   }
}

There may be better options of combining the classes, but I'm not sure the exact functionality you expect out of this.

server_crash 64 Postaholic

Cool problem. We should see who can come up with the best programmatical solution ;)

server_crash 64 Postaholic

Thanks guys ;)

If anyone loves me then just send me a gift($$$$) via paypal.

server_crash 64 Postaholic

Do you know how to create one via the commandline?

server_crash 64 Postaholic

There is no language called 'best'. That's the bottom line.

On a serious note, however, you can't get any easier than vb.net with visual studio. Of course, you might should listen to vegaseat. C# is definately catching on.

server_crash 64 Postaholic

But guys Java, J2EE ,.Net is currently on demand.

I'm sure ALL programmers who know Java, just don't know Java.

server_crash 64 Postaholic

You could simply loop through I guess:

bool anyNegatives(int nums[], int size)
{
   for (int i=0; i<size; ++i)
   {
      if (nums[i] < 0)
      {
          return true;
      }
   }
   return false;
}

Pretty simple. If you encounter one, then you can break.

server_crash 64 Postaholic

I'd personally rather use setLocation(int x, int y). I like using the setSize() property for the overall container and using setBounds(int,int,int,int) for inner containers.

server_crash 64 Postaholic

Do you mean a tree? ;)
I'd say use a map or something along those lines. If there's a java equivalent of the c++ multimap, then go that route.

server_crash 64 Postaholic

Did you read my reply at all? You wont be able to play a burnt dvd unless you decrypt it. Secondly, a normal dvd is over 8 gigs(multilayer) and a blank dvd is only about 4 gigs....That's why I ask if you shrank the video. Once you do all that, it will be in perfect .vob format for you to burn.

server_crash 64 Postaholic

Alienware ALL the way. I wouldn't buy anything else. I have a Dell which is had nothing but SERIOUS problems ever since I bought it. Their tech support is decent under warranty, but the quality is crap. We actually have two of the same Dell laptops. One with major issues, the other with small issues, but has some growing concern.


Anyways, take a look at what alienware offers. If you want a desktop replacment, then they have it.

server_crash 64 Postaholic

Pretty cool. I actually started writing a console connect four game in c++ this morning. I'm done with it, but it's only two player. Shortly I'll be working on it for human vs computer.

server_crash 64 Postaholic

I don't know much, but I think your best bet would be consumer credit counsiling to see what they say. If you do think about filing bankrupcy, then at least take a look into the chapter 13 plan.

Not sure if that will help or not. I don't know much about the subject.

server_crash 64 Postaholic

I think it is the sound package and you create an AudioClip object and call the .play() method on it.