codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  loop, break problem!  dulcinea26 at 10:36 on Tuesday, March 28, 2006
 

Hi all;

I have a problem regarding my loop.The code is below:


StringTokenizer wordFactory = new StringTokenizer(myNewString);

while (wordFactory.hasMoreTokens())
{
//get the next word from the sentence
Aword = wordFactory.nextToken();
long time = System.currentTimeMillis();

}


let me explain how the code works.

the input is "aaa bbb ccc" and it is suppose to print one by one and the output will be printed out one by one, aaa then bbb and then ccc.

i do this method since i want to track the time of each word with brute force method :

for(char r = 'a'; r <= 'z'; r++){
first = r;
for(char s = 'a'; s<='z'; s++){
second = s;
for (char t = 'a'; t <= 'z'; t++){
third = t;
anotherWord=String.valueOf(first)+second+third;
if(anotherWord == Aword){
System.out.print(anotherWord)
//track the time when anotherWord == Aword
}
}
}
}

my problem is, once "aaa" has been detected by the code, how can i proceed to detect "bbb" and "ccc"?

i really appreciate anyone's help. if the problem explanation is quite blur, u can ask me to explain in detail!

thanx in advance!

regards;
dulcinea

  Re: loop, break problem!  miteshbhimjiyaani at 04:25 on Wednesday, March 29, 2006
 

hi
if(anotherWord == Aword){
System.out.print(anotherWord)
//track the time when anotherWord == Aword
}

replace with
if(anotherWord .equals(Aword)){
System.out.print(anotherWord);
break;

//track the time when anotherWord == Aword
}

  Re: loop, break problem!  crwood at 06:29 on Wednesday, March 29, 2006
 


import java.util.StringTokenizer;

public class Test
{
public static void main(String[] args)
{
String input = "aaa bbb ccc";
StringTokenizer tok = new StringTokenizer(input);
while(tok.hasMoreElements()) {
String token = tok.nextToken();
char first, second, third;
String theword;
for(char r = 'a'; r <= 'z'; r++) {
first = r;
for(char s = 'a'; s <= 'z'; s++) {
second = s;
for (char t = 'a'; t <= 'z'; t++) {
third = t;
theword = String.valueOf(first) + second + third;
if(theword.equals(token)) {
System.out.println(theword);
r = (char)'z'+1;
break;
}
}
}
}
}
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Unix command output displayed 0 in browser
•  Perl 5.6 PPM is not working
•  Re: Need Code
•  telnet to a system with username and password using perl
•  Re: validating drop down
•  Code to encrypt the Password or any string
•  Re: ?0:1; ?????? What this means?
•  Re: Need some help making a C++ program
•  Re: urgent........regarding to swings


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007