2013-04-04 69 views
0

如何从使用java的文件添加单词?从文件java中添加单词

+0

这不会解决任何问题,但你可以改变这一点: 的for(int i = 0;我 WereWolfBoy 2013-04-04 12:17:48

+0

为什么这个问题改变了,并且是我对前一个问题的答案不被接受的答案? :| – WereWolfBoy 2013-04-22 08:21:01

回答

0

你只是将它与其中一个孩子比较。

for(int i=0; i<rootChildren.length; i++){ 
        Node rootChild = rootChildren[i]; 
        //see if the addChar1 already exists in the tree 
        //if it doesn't 

        if(!rootChild.equals(addChar1)){ 
         //add the addChar1 as a child of the root 
         root.addChild(addChar1); 

        } 
        else{ 
         System.out.println(addChar1.getItem() + " Exists in the tree already"); 
        } 

在它不等于第一个孩子后已添加它。你想看看它是否等于任何一个孩子。你可以做的是这样的:

int equalsnrofchildren = 0; 
    for(Node rootChild : rootChildren){//loops through all the children 
         //see if the addChar1 already exists in the tree 
         //if it doesn't 

         if(rootChild.equals(addChar1)){ 
          equalsnrofchildren++; 

         } 
    } 

    if(equalsnrofchildren == 0){ 
    root.addChild(addChar1); 
    }else{ 
System.out.println("already exists.."); 
} 
+0

谢谢,解决了这个问题! – ciastkoo 2013-04-04 12:33:14

+0

没问题,队友。 – WereWolfBoy 2013-04-04 12:34:18