0
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 を印刷しても何も返されません。

他に何がありますか?

4

2 に答える 2

3

でコードを変更する

int i = 0; i < len; i++

vowels.indexOf(sentance.toUpperCase().charAt(i)) < 0

定数のみが出力されます。

于 2013-02-12T16:21:10.340 に答える
0

このコード::

    for (int i = 0; i >= len; i++) {
        if (vowels.indexOf(sentance.toUpperCase().charAt(i)) > 0) {
            newSentance += sentance.charAt(i);
        }
    }

次のようにする必要があります。

    for (int i = 0; i < len; i++) {
        if (vowels.indexOf(sentance.toUpperCase().charAt(i)) >= 0) {
            newSentance += sentance.charAt(i);
        }
    }
于 2013-02-12T16:16:45.897 に答える