2016-10-16 2 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"); 
    } 





} 

}