Friday, October 13, 2006

Data Validation Example

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

No comments: