Hello everyone. Thank you in advance for your time. I want this program to generate user defined amount of random number between 0-999 and then sort them in ascending order. It works properly without the bubble sort, but when i add the bubble sort it gives me a ridiculous output. like below

Output

Please Enter the amount of random numbers you want to generate : 2

229

Sorted array

229

891

Sorted array

891

But i need it as follows

Please Enter the amount of random numbers you want to generate : 3

229

45

251

Sorted array

45

229

251

My code so far

Code:

package random;

import java.util.Random;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner (System.in);

System.out.print("Please Enter the amount of random numbers you want to generate : ");

Random dice = new Random();

int number;

int input = in.nextInt();

for(int counter = 1; counter<=input; counter++){

number = dice.nextInt(999); // Randomly generated values between 0-999

{

int nums [] = {number}; // Passing randomly generated values to array

int a,b,t;// Integers for bubble sorting

int size = nums.length;

for(int i=0; i< size; i++)

System.out.println(nums[i]);// Display original array

// Sorting

for (a=1; a<size; a++)

for(b=size-1; b>=a;b--){

if(nums[b-1]> nums[b]){

t = nums[b-1];

nums[b-1] = nums[b];

nums[b] = t;

}

}

//Display sorted array

System.out.println("Sorted array");

for(int i =0; i<size; i++)

System.out.print(""+ nums[i]);

System.out.println();

}

}

}

}