To Check a Number Whether is it Prime or Not.
private void CheckButtonActionPerformed(java.awt.event.ActionEvent evt) {
int N= Integer.parseInt(t1.getText());
int i;
for(i=2;i<=N/2;i++)
{
if(N%i==0)
{ r.setText("Not a Prime No. ");
break;
}
}
if(i>N/2)
r.setText("Prime No. ");
}
private void ClearButtonActionPerformed(java.awt.event.ActionEvent evt)
{
t1.setText("");
r.setText("");
}
Comments
Post a Comment