java - try/exception for integer or double or string -
how differentiate integer , double. example if wanted integer , verify it. if integer output "you correct" else "you entred wrong. try again".
import javax.swing.*; public class inputexceptions { private static int inputint; private static double inputdouble; public static int inputint() { boolean inputok = false; while (inputok == false) { inputint = integer.parseint(joptionpane.showinputdialog("enter integer")); try { inputok = true; } catch (exception e) { joptionpane.showmessagedialog(null,"*** error: value entered not integer ***"); } } return inputint; } public static void main(string[] args) { joptionpane.showmessagedialog(null,"*** integer correct input: " + inputint() + " ***"); } }
Comments
Post a Comment