Input Checker in Java

Download
Download is available until [expire_date]
  • Version
  • Download 39
  • File Size 3.11 KB
  • File Count 1
  • Create Date May 12, 2016
  • Last Updated May 12, 2016

Input Checker in Java

Input Checker in Java

It is a java program that will check in the character or string that you have input or entered matches to the criteria set in the program. If a match is found the program will display a message if not a message also displays saying that your input is invalid, which means that it has no match to the given criteria.

Source code:

import javax.swing.*;
public class InputCheckerGUI
{ 
public static void main(String args[]) {

String selected ; 
String cont="n";

do
{
	selected=JOptionPane.showInputDialog(null, "Please select a letter:" + "
" + "a" + "
" + "b" + "
" + "c" + "
" + "d");

if (selected.matches("a")){
	JOptionPane.showMessageDialog(null,selected + " is for apple");
} else if (selected.matches("b")){
	JOptionPane.showMessageDialog(null,selected + " is for ball");
}else if (selected.matches("c")){
	JOptionPane.showMessageDialog(null,selected + " is for cat");
} else if (selected.matches("d")){
	JOptionPane.showMessageDialog(null,selected + " is for dog");
}
else
{
JOptionPane.showMessageDialog(null,"invalid input");	
}

	
	cont =	JOptionPane.showInputDialog(null,"Try Again? (press y or n) ");
	}while (cont.matches("y"));

JOptionPane.showMessageDialog(null,"Program closing"  );


	}
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.