2013-06-23 77 views
0

这是if语句是怎么写的如果声明没有被读取

  //Check and see if current is less than the next character. 
      if (node.thisChar().charAt(0) < current.thisChar().charAt(0)) 
      { 
       temp = current; 
       previous = node; 
       node.next = current; 

       System.out.println("Its in here"); 
       break; 
      }// end if 

      previous = current; 
      current = current.next; 

     //what was empty at the end of the list now has a new node being linked. 

     System.out.println(current.thisChar().charAt(0) + " This is the current"); 
     System.out.println(node.thisChar().charAt(0) + " This is the new character"); 
     System.out.println("Character " + node.thisChar() + " has been added"); 

问题与,突出if语句。例如,如果节点字母'd'小于当前字母'f',if语句将最终被跳过,导致未排序的列表。放置在if语句中的输出永远不会到达。奇怪的是,我的输出将如何显示thisChar().CharAt()thisChar只是返回字符,它是String类型)的字符;表明这些陈述正在起作用。除非问题出在String类型的变量上,否则我不知道if语句是怎么回事。任何建议将被认真考虑。

+1

小问题,如此庞大的代码张贴 – Joe

+0

我会编辑它 – GemToughy

+0

如果“节点”小于“当前”,则您的条件为真。如果你想在这种情况下跳过*,你必须反转条件。 –

回答

0

你可以交替使用的方法

string.compareTo(String) 

例如比较

String s1, s2; 
//blabla 
//giving string variables values 
s1.compareTo(s2) 

有关更多信息,请参见本link

+0

我假设你的意思是'比较'而不是'比较' – FDinoff

+0

是的。我的错 !!! –

+0

我会看看这是否有效,但它与我在if语句中所做的相同。我的System.Out可以准确地打印输入的字母,这让我认为if语句如何进行比较只是出了问题。希望这会起作用 – GemToughy