Why is this value always true? I just can’t figure out how to have a boolean that “blinks” every second.
long millis = System.currentTimeMillis();
boolean blink = (Math.floor(millis/1000 + 0.5)==Math.floor(millis/1000));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is how I’d do it
This uses the modulo
%operator to determine how far into a repeating two second window the current time is. Then it sees if it’s in the first half (0 to 999) of the window or the second half (1000 to 1999). This will result in a boolean value that alternates true and false every second.