You can't do if (int i = 0)
, because assignment returns the assigned value (in this case 0
) and if
expects an expression that evaluates either to true
, or false
.
On the other hand, if your goal is to check, whether jTextField.getText()
returns a numeric value, that can be parsed to int
, you can attempt to do the parsing and if the value is not suitable, NumberFormatException
will be raised, to let you know.
try {
op1 = Integer.parseInt(jTextField1.getText());
} catch (NumberFormatException e) {
System.out.println("Wrong number");
op1 = 0;
}