I have this code where I loop a code using a timer, in which it would add or minus a random number. When the current number reaches below zero, it should print as "The Number is now in negative" an when it reaches 100 and above, it would print as "The Number reached 100+". Problem is, I want it to print only once if it fluctuates in negative or 100+ Here is my public void() method
public void run() {
Random myRand = new Random();
int incdec = myRand.nextInt(2);//0 for Increasing 1 for Decreasing
double change = myRand.nextInt(1000) / 100.0;//Random double number ranging up to 10.0
if(incdec == 0){
num=num+change;
num= Math.round(num* 100.0) / 100.0;
System.out.println("Increase: "+change );
System.out.println("Current num: "+num);
if(num>= 100){
System.out.println("The Number reached 100+");
}
else if(num<= 0){
System.out.println("The Number is now in negative");
}
System.out.println("");
}
This one works but it would repeatedly print as it loops in public void run().