dimanche 16 octobre 2016

Using If statements with indexOf from a Dialogbox

the program here is supposed to look for specific sentence ending format. whether if its declarative, Exclamatory or a Question mark. I however am having issues trying to configure the Dialog box. I'm also unsure if the if statement has been properly configured to return the correct response if said sentence is inputed correctly with one of the three needed.

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");
}





}

}

Aucun commentaire:

Enregistrer un commentaire