hello again,
I found a quite strange problem.
I found a way to create a prime numbers detectors
my problem is i succeeded to create a condition for a non prime number but after many attemps I can’t find the right condition to give to the code for recognize a prime number only.the code freeze.
do you have any idea ?? thanks a lot
final int INPUT=0;
final int CALC=1;
int state = INPUT;
int modulo;
String numInput="";
int num=0;
void setup() {
size(800, 500);
}
void draw() {
background(0);textSize(50);textAlign(CENTER);
fill( 0, 255, 0);
text(“Entrez un nombre”, 400, 170);
fill(255, 130, 0);
textSize(80); text(numInput+caret(),400, 250);
if (! numInput.equals("")&&state == CALC) {
for (int diviseur = 2; diviseur <num; diviseur=diviseur+1) {modulo = num%diviseur;print(num);print(" “);print(diviseur);print(” ");println(modulo);
if (modulo==0) {background(0);
textSize(180);fill(0, 255, 0);text(num,400,200 );
textSize(80);fill(255, 130, 0);text("n'est pas premier",400 ,290);
textSize(120);fill(0, 255, 0);text(diviseur+"x"+(num/diviseur),400,450);
textSize(20);text(diviseur+"x"+(num/diviseur)+"="+num,700,400);
textSize(20);fill(100);text((diviseur+1)+"x"+(num/diviseur)+"="+((diviseur+1)*(num/diviseur)),700,420);
text((diviseur+2)+"x"+(num/diviseur)+"="+((diviseur+2)*(num/diviseur)),700,440);
text((diviseur+3)+"x"+(num/diviseur)+"="+((diviseur+3)*(num/diviseur)),700,460);
text((diviseur+4)+"x"+(num/diviseur)+"="+((diviseur+4)*(num/diviseur)),700,480);
text((diviseur-1)+"x"+(num/diviseur)+"="+((diviseur-1)*(num/diviseur)),700,380);
text((diviseur-2)+"x"+(num/diviseur)+"="+((diviseur-2)*(num/diviseur)),700,360);
text((diviseur-3)+"x"+(num/diviseur)+"="+((diviseur-3)*(num/diviseur)),700,340); }
} }}
void keyPressed() {
if (key==ENTER||key==RETURN) {
//submit
num =
int(numInput);
state = CALC;
return;//leave
}
if (key==ESC) {
state=INPUT;
key=0;
return;
}
if (key==BACKSPACE) {
if (numInput.length()>0)
numInput=numInput.substring(0, numInput.length()-1);
return;
}
if (key==CODED)
return; // leave
// int keyNum = Character.getNumericValue(key);
numInput += key;
}
String caret() {
// Blinking cursor: return | or blank
if (millis() % 1000 < 500)
return “|”;
else
return " ";
}