I need to have a loop generate random numbers until a random number is smaller than the previous number. here are some clarifying examples:
ex 1: 23, 59, 81, 35, end
ex 2: 23, 4, end
ex 3: 3, 26, 38, 39, 41, 41, 72, 79, 84, 91, 96, 92, end.
The error is in the loops. I'm trying to compare two random outputted values from the loop, but I honestly don't remember how. I've tried for loops and while loops and nothing has worked thus far. I am writing this in java Any help would be appreciated. Thanks!
public static void main(String args[])
{
int max = 100;
int min = 1;
int range = max - min + 1;
int r=(int)(Math.random()*range)+min;
for(int i=0; i<=100; i=i+1){
System.out.println(r);
r=(int)(Math.random()*range)+min;
r=r;
if(r<r){
break;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire