2016-10-16 1 views
0

ここでのプログラムは、特定の文末形式を探すことになっています。 宣言的、感嘆符的、または疑問符であれば。私はしかし、ダイアログボックスを構成しようとする問題があります。私はまた、if文が適切な応答を返すように適切に設定されているかどうかも確かではありません。DialogboxのindexOfのIf文を使用する

import javax.swing.JOptionPane; 
public class P45 
{ 
public static void main(String [] args) 
{ 
String s = JOptionPane.showMessageDialog("Please input sentence."); 

if (s.indexOf('!')!=0){ 
JOptionPane.showMessageDialog(null, " Sentence is exclaimatory"); 
} 
else if (s.indexOf('.')!=0){ 
JOptionPane.showMessageDialog(null, " Sentence is a statement"); 
} 
else if (s.indexOf('?')!=0){ 
JOptionPane.showMessageDialog(null, " Sentence is a question"); 
} 





} 

} 

答えて

0

私は最終的には私もif文の正しい形式を見つけ、間違っていたものを入力対話とショーのメッセージ間の単純なタイプミスとの違いを考え出しました。

import javax.swing.JOptionPane; 
public class P45 
{ 
public static void main(String [] args) 
{ 
String s = JOptionPane.showInputDialog("Please input sentence."); 

if (s.indexOf('!')!=-1){ 
    JOptionPane.showMessageDialog(null, " Sentence is exclamatory"); 
    } 
    else if (s.indexOf('.')!=-1){ 
    JOptionPane.showMessageDialog(null, " Sentence is a statement"); 
    } 
    else if (s.indexOf('?')!=-1){ 
    JOptionPane.showMessageDialog(null, " Sentence is a question"); 
    } 





} 

}