Pessoal não consigo achar o erro existente aqui…
Na verdade ele não dá erro… ele apenas não diz se o numero é primo ou não se for abaixo de dex
eis o código:
import java.io.BufferedReader;
import javax.swing.JOptionPane;
/*
- Primos.java
- Created on 15 de Novembro de 2006, 15:26
*/
/**
*
-
@author User
*/
public class Primos extends javax.swing.JFrame {/** Creates new form Primos */ public Primos() { initComponents(); }
static boolean result; static BufferedReader num; static int x; static String a;
/** This method is called from within the constructor to
-
initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is
-
always regenerated by the Form Editor. */ // <editor-fold defaultstate=“collapsed” desc=" Generated Code "> private void initComponents() { tfnum = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jButton1 = new javax.swing.JButton();
getContentPane().setLayout(null);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle(“N\u00fameros Primos”); getContentPane().add(tfnum); tfnum.setBounds(50, 40, 110, 19);
jLabel1.setText(“Digite um n\u00famero:”); getContentPane().add(jLabel1); jLabel1.setBounds(50, 20, 120, 15);
jButton1.setText(“Calcular”); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });
getContentPane().add(jButton1);
jButton1.setBounds(60, 70, 90, 25);java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-224)/2, (screenSize.height-155)/2, 224, 155); }// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: int num, result; num = Integer.parseInt(tfnum.getText()); result = num%2; if (result == 0){ JOptionPane.showMessageDialog(null, “Este número não é primo”); }else { int raiz = (int)Math.sqrt(num) + 1; for(int i=3;i<raiz;i+=2) { if(num % i == 0) { break; } JOptionPane.showMessageDialog(null, “Este Número é primo”); } } }
private int resutl;
/**
-
@param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Primos().setVisible(true);
}
});
}
private String getText(String string) { return null; }
// Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JTextField tfnum; // End of variables declaration
-
}
Alguem poderia me ajudar?
Obrigado