previous value of same variable
How can I compare previous value of same variable(result) with current value.
Example, result 1 > result 2 or not, result 2 > result 3 or not, result 3 > result 4 or not, result 4 > result 5 or not.
Code :
import java.util.Random;
public class Test {
public static void main(String args[]){
double A = 5;
Test Cal = new Test();
Cal.run(A);
}
void run(double A){
Random random = new Random();
double result;
int i = 0;
do{
i++;
result = A + random.nextGaussian() / 2;
System.out.println(result);
}while(i<5);
}
}
regard
ray
Re: previous value of same variable
Re: previous value of same variable
Keep track of the previous result in a temporary variable.
Example work-flow:
Init. 2 variables, last val and current val.
Get current val, set last val equal to current val.
for i = 1, i < 5, ++i
get a new current val
compare it to the last val
set last val equal to current val
Re: previous value of same variable
Quote:
Originally Posted by
helloworld922
Keep track of the previous result in a temporary variable.
Example work-flow:
Init. 2 variables, last val and current val.
Get current val, set last val equal to current val.
for i = 1, i < 5, ++i
get a new current val
compare it to the last val
set last val equal to current val
Perfect work-flow.
I understand and can do it.
Thank you very much for your help.
ray
:)