I'm having an issue sorting my random number array.
What I'd like to do is make an if statement to make sure arr[0] is always greater than arr[1].
Why? Well, my program generates two random numbers from 0 - 99, and it does simple math problems such as subtraction and division. Since you can't divide 55 / 99 properly, the first arr[0] should always be larger than arr[1].
Here's where I'm at and thanks for your help!
public static int[] randomNumbers(){
Random obj = new Random();
int arr[] = new int[2]; //init array to hold 2 numbers
arr[0] = obj.nextInt(99); //number 1 randomized 0 - 9 // sort array
arr[1] = obj.nextInt(99); //number 2 randomized 0 - 9
//do compare to make sure arr[0] is always greater than arr[1]
//but how???
return arr;
/*int rgen = obj.nextInt(10); //first number has to be larger than second 0 - 10
int rgen1 = obj.nextInt(9); //random 0 - 9
int randomNumber = rgen + rgen1; //stores the answer*/
}
if(arr[0] < arr[1])?