try {
num = Integer.parseInt(userText.getText());
for (i = 1; i <= num; i++) {
if (num % i == 0)
textFieldAns.setText(" "+i);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Please Enter Valid number");
}
The output doesn't seem to display the factors of the number in a form of a looping statement.