You never increment low so it's always the same which causes the infinite loop.
You never increment low so it's always the same which causes the infinite loop.
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 declaredpublic 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 …
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.
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.
Plus, you haven't asked a question. If you did, I might be able to answer it.
I am learning JavaScript and am lost.
Yes, you are lost. This is a JSP forum, not javascript. ;)
What do you mean you don't know what node to look at?
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.
startsWith(String prefix)
endsWith(String postfix)
So what's your question? I see nothing but a bunch of code in need of a few band aids, but no question.
Hitler would be a good one. You could definately get some good/bad scenarios out of him.
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?
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).
Take out the break statements if you want all them to execute, but that probably means your logic is flawed.
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.
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.
Do you mind showing me the loop?
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.
Loop not written properly. [Probably an infinite loop]
for (int i=10; i>=0; i++)
{
}
That would be an example.
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.
Get sex
Have you illustrated some of these ideas? It could help.
I thought it was strspn(parameters); ?
You could pick about any of the constitution framers.
J2ME, I would guess.
Use a file filter. I think there's an accept() method that you can provide a default extension in, but not sure.
extensions maybe?
Binary is suppose to be .dat
Test is .txt or .text
I totally don't understand what you're asking for.
What do you mean from a different context?
To close:
System.exit(0);
To open:
Just create an instance
Multiple opinions are always good.
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.
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 ;)
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.
If I understand correctly, you can set the visibility:
Component.setVisible(false);
Or even better, set the editability:
Component.setEditable(false);
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 ;)
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.
Cool problem. We should see who can come up with the best programmatical solution ;)
Thanks guys ;)
If anyone loves me then just send me a gift($$$$) via paypal.
Do you know how to create one via the commandline?
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.
But guys Java, J2EE ,.Net is currently on demand.
I'm sure ALL programmers who know Java, just don't know Java.
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.
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.
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.
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.
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.
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.
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.
I think it is the sound package and you create an AudioClip object and call the .play() method on it.