我真的很想在這裏。我試圖在字符串中反轉這些單詞。我正在嘗試使用StringUtils並完成導入。爲什麼我會得到和「無法找到符號。方法...」?「找不到符號」?
這裏是我的代碼:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mkrsassignment10;
import com.sun.xml.internal.ws.util.StringUtils;
/**
*
* @author mso_
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Q1
//int index;
String sentence = "is this a sentence or is it not ";
// 1a
String[] myStringArray = sentence.split(" "); //Split the sentence by space.
String wordLongest = myStringArray[0]; //assign longest word to the first word
for (int i=0; i < sentence.length(); ++i) { //loop through the sentence to find the longest word
if(wordLongest.length() < myStringArray.length)
wordLongest = myStringArray[i];
else
break;
}
System.out.println("The word is: " + "'"+ wordLongest +"'" + " and it is " + wordLongest.length() + " characters long");
// 1b
//for (int i = 0; i < myStringArray.length; i++) {
// myStringArray.toString();
// else
// break;
// 1c
String reversed = StringUtils.reverseDelimited(sentence, " "); // <--- here is the error
System.out.println("Reversed words:" + reversed);
// 1d
sentence = new StringBuffer(sentence).reverse().toString();
System.out.println("Reversed String : " + sentence);
}
}
你能發佈你從編譯器得到的錯誤消息嗎? (整個消息,而不僅僅是它的一部分) – coobird 2011-05-02 12:52:42
使用'com.sun.xml.internal'內的任何東西是非常糟糕的做法。我強烈建議你找到解決這個問題的另一種方法(例如使用Apache Commons Lang的'StringUtils') – skaffman 2011-05-02 12:57:02
yep「找不到符號。symbol:method reverseDelimited(java.lang.String.java.lang.String)。location :class com.sun.xml.internals.ws..util.StringUtils「 – Morten 2011-05-02 12:58:07