import javax.swing.*;
public class DataValidationExample {
public static void main(String[] args) {
String inputStr;
double marks;
do{
inputStr = JOptionPane.showInputDialog(null,"Enter your marks");
marks = Double.parseDouble(inputStr);
// show error message if invalid data
if (marks < 0 || marks>100)
JOptionPane.showMessageDialog(null,
"Enter marks between 0 and 100");
} while (marks < 0 || marks>100); // end while
JOptionPane.showMessageDialog(null,
"You scored " + marks);
} //end main
} //end class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment