current position:Home>Java random numbers are sorted in the array

Java random numbers are sorted in the array

2022-02-02 20:25:15 CSDN Q & A

use Math.random() Function generation 10 Random data , In a one-dimensional array , And sort the output .




Refer to the answer 1:

You just put random numbers in the array , Doing a bubble sort Isn't the output over




Refer to the answer 2:



Refer to the answer 3:
import java.util.*;public class A {    public static void main(String[] args) {        int a[] = new int[10];        for(int i = 0;i < 10;i++){            a[i] = (int)(Math.random()*10);        }        Arrays.sort(a);        for(int i = 0;i < 10;i++){            System.out.print(a[i] + " ");        }    }}



Refer to the answer 4:



Refer to the answer 5:

Xiaowu answers for the third brother : You can use circular nesting to write a random number first , And then use sort Just sort it out




Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022025137343.html

Random recommended