Hey everyone,
I have written some code to find all of the e characters that occur within the command line arguments to my program. If there are no e's then there are no problems with the code execution, additionally this code compiles fine and runs fine... "sort of". The thing is that any command line argument that has an e in it causes the program to simply hang
I have never waited long enough to see if this program will do what it is supposed to do, however on a Pentium 4 I can't see why it should take longer than a couple of seconds.
The code is as follows
class ExerciseTenPointThree
{
public static void main(String[] args)
{
if(args.length > 0)
{
EasyGoing findEs = new EasyGoing(args);
System.out.println("Your strings contained " + findEs.findEs() + " e's
");
}
else
{
System.out.println("Please supply one or more command line arguments.");
}
}
}
class EasyGoing
{
private String[] allStrings;
private int masterCountOfEs;
EasyGoing(String[] progArguments)
{
this.allStrings = progArguments;
}
public int findEs()
{
for(int i=0; i<allStrings.length; i++) //Performed for each program argument string!
{
String currentString = allStrings;
while(currentString.indexOf("e") != -1)
{
int location = currentString.indexOf("e");
if(location != -1)
{
masterCountOfEs++; //An "e" has been found
currentString = currentString.substring(location);
}
}
}
return masterCountOfEs;
}
}
I figure that there is something wrong with reusing the same String name over and over... so I probably need to modify the use of the currentString variable. However I am not 100% sure of what is going on, so any suggestions / input will be really appreciated.
Thanks heaps
Regards
Davo
I have written some code to find all of the e characters that occur within the command line arguments to my program. If there are no e's then there are no problems with the code execution, additionally this code compiles fine and runs fine... "sort of". The thing is that any command line argument that has an e in it causes the program to simply hang
I have never waited long enough to see if this program will do what it is supposed to do, however on a Pentium 4 I can't see why it should take longer than a couple of seconds.
The code is as follows
class ExerciseTenPointThree
{
public static void main(String[] args)
{
if(args.length > 0)
{
EasyGoing findEs = new EasyGoing(args);
System.out.println("Your strings contained " + findEs.findEs() + " e's
}
else
{
System.out.println("Please supply one or more command line arguments.");
}
}
}
class EasyGoing
{
private String[] allStrings;
private int masterCountOfEs;
EasyGoing(String[] progArguments)
{
this.allStrings = progArguments;
}
public int findEs()
{
for(int i=0; i<allStrings.length; i++) //Performed for each program argument string!
{
String currentString = allStrings;
while(currentString.indexOf("e") != -1)
{
int location = currentString.indexOf("e");
if(location != -1)
{
masterCountOfEs++; //An "e" has been found
currentString = currentString.substring(location);
}
}
}
return masterCountOfEs;
}
}
I figure that there is something wrong with reusing the same String name over and over... so I probably need to modify the use of the currentString variable. However I am not 100% sure of what is going on, so any suggestions / input will be really appreciated.
Thanks heaps
Regards
Davo