I am trying to validate the input of a user so when they enter an invalid provin
ID: 3614341 • Letter: I
Question
I am trying to validate the input of a user so when they enter an invalid province. In this case an invalid province isanything not NS or NL or NB. However, when l run this program it isnot even working. What am l doing wrong can someone please helpimport javax.swing.*;
public class tatenda
{
public static void main (String [] geek )
{
Boolean keepgoing = true;
String input ;
while (keepgoing)
{
input=JOptionPane.showInputDialog("Enter the code of your province"+
" Press q when you want toquit.");
while (!input.equals("NS")||!input.equals("NB")||!input.equals("NL"))
{
input=JOptionPane.showInputDialog("Enter the code of yourprovince");
JOptionPane.showMessageDialog(null, "You entered the wrongprovince");
}
if(input.equals("q"))
{
keepgoing=false;
}
else if(input.equals("NS")||input.equals("NB")||input.equals("NL"))
{
System.out.print("I love You");
}
}
}
}
Explanation / Answer
import javax.swing.*; public class Tatenda { public static void main (String [] geek ) { Boolean keepgoing = true; String input; input=JOptionPane.showInputDialog("Enter thecode of your province" + " Press q when you want toquit."); while(keepgoing) { if(input.equals("NS")||input.equals("NB")||input.equals("NL")) { System.out.print("I love You"); keepgoing= false; } elseif(input.equals("q")) { keepgoing=false; } // else //while (!input.equals("NS")||!input.equals("NB")||!input.equals("NL")) else { JOptionPane.showMessageDialog(null, "You entered the wrongprovince"); input=JOptionPane.showInputDialog("Enter the code of yourprovince"); } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.