有一个值他无时无刻都在赋值,赋的值也没有规律,怎么让现在的值 和500毫秒以后的值进行比较啊?
有一个值他无时无刻都在赋值,赋的值也没有规律,怎么让现在的值 和500毫秒以后的值进行比较啊?求解!!! --------------------编程问答-------------------- 感觉闻到了一丝哲学和物力的味道
用个hashmap
保存当前值的值和时间
当过500毫秒后。在保存一个。比较。 --------------------编程问答--------------------
package test.test1;
public class CompareTest {
public static int i = 0;
public static int result = 0;
public static int a = 0;
public static int b = 0;
public static void main(String[] args) {
new Thread(){
public void run() {
while(true){
if(i<100000000){
i++;
}
else{
i=0;
}
}
};
}.start();
compare();
}
public static void compare() {
new Thread() {
public void run() {
a = i;
System.out.println("a = "+a);
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
}
b = i;
System.out.println("b = "+b);
int temp = b-a;
System.out.println("差值 = " + temp);
};
}.start();
}
}
补充:移动开发 , Android