import javax.swing.JOptionPane;
public class Indexof {
public static void main(String[] args) {
String newSentance = "";
String sentance = JOptionPane.showInputDialog("Enter sentance");
String vowels = "AEIOU";
int len = sentance.length();
for (int i = 0; i >=len; i++)
{
if(vowels.indexOf(sentance.toUpperCase().charAt(i))>0)
{
newSentance+=sentance.charAt(i);
}
}
System.out.println(newSentance);
}
}
我越來越沒有錯誤在NetBeans尚未打印newSentance 的。長度肯定是因爲它的工作時,它仍然沒有返回如果打印正確返回數字爲什麼這不起作用[試圖打印出一個新的句子時所有的常數]
它還能是什麼?
我不認爲你的JOptionPane返回一個字符串,因此「sentance」等於零。由於len爲零,for循環不會運行,newsentance不會更新,也不會打印任何內容 – 2013-02-12 16:15:01
'length'完美運行,因爲您正在打印原始句子的長度。如果你的'sentance'不包含任何元音,你的newSentance中就不會有任何變化。 – 2013-02-12 16:15:40