Answers
Sep 14, 2010 - 05:52 AM
i think that you should try this program:
boolean correctForm = false;
if(txtQuestion.getText().length() > 10)
{
correctForm = true;
}
else
{
JOptionPane.showMessageDialog(null, "Question missing!");
}
boolean correctForm = false;
if(txtQuestion.getText().length() > 10)
{
correctForm = true;
}
else
{
JOptionPane.showMessageDialog(null, "Question missing!");
}
Apr 27, 2011 - 05:36 AM
public class Main {
/**
* This method checks if a String contains only numbers
*/
public boolean containsOnlyNumbers(String str) {
//It can't contain only numbers if it's null or empty...
if (str == null || str.length() == 0)
return false;
for (int i = 0; i < str.length(); i++) {
//If we find a non-digit character we return false.
if (!Character.isDigit(str.charAt(i)))
return false;
}
return true;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main main = new Main();
System.out.println(main.containsOnlyNumbers("123456"));
System.out.println(main.containsOnlyNumbers("123abc456"));
}
}
Add New Comment