Need help to translation program

HI

i need a bit help to know what's wrong here... the problem is that it only will translate the first word. I need it to translate a sentence by using the java.util.Scanner. Heres the code:

import java.util.*;

publicclass Main

{

publicstaticvoid main(String[] args)

{

java.util.Scanner tastatur =new java.util.Scanner(System.in);

HashMap<String,String> ord =new HashMap<String,String>();

ord.put("hello","hej");

ord.put("my","mit");

ord.put("name","navn");

ord.put("is","er");

ord.put("and","og");

ord.put("i","jeg");

ord.put("am","er");

ord.put("have","har");

String engelsk = tastatur.next();

for (String dansk : engelsk.split("\\b") )

{

String da = ord.get( dansk );

if (da ==null) da=dansk;

System.out.print( da );

}

}

}

Sorry for my bad english...

[1890 byte] By [fredd1a] at [2007-11-27 3:44:56]
# 1
.next() only gives the next complete token.You should use something like thiswhile (hasNext()) { String token = scn.next();}
kdajania at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...
# 2
Where should i insert that?BTW thanks for post=DMessage was edited by: fredd1
fredd1a at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...
# 3

To tell you the truth, I am not too familiar with this scanner class. However, I think the code would have to look like this.

while (tastatur.hasNext()) {

String engelsk = tastatur.next();

for (String dansk : engelsk.split("\\b") )

{

String da = ord.get( dansk );

if (da == null) da=dansk;

System.out.print( da );

}

}

post back, let us know what happens

kdajania at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...
# 4
actually, I don't think that is right at all.Check out the scanner API, it will give you better insight.
kdajania at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...
# 5
ok thx =P
fredd1a at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...
# 6
Others have a suggestionsthe (hasnext) mothod dosent work at netbeans
fredd1a at 2007-7-12 8:48:37 > top of Java-index,Java Essentials,New To Java...