Skip to main content
deleted 113 characters in body; edited title; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Selection sort in Java Sorting random non-repeating numbers

I am working on a program in which 10000 random no repeatnon-repeating numbers are selectively sorted into ascending order.

I have written the following code:order"

I know I asked a similar question earlier, but I would appreciate any help.

Selection sort in Java

I am working on a program in which 10000 random no repeat numbers are selectively sorted into ascending order.

I have written the following code:

I know I asked a similar question earlier, but I would appreciate any help.

Sorting random non-repeating numbers

I am working on a program in which 10000 random non-repeating numbers are selectively sorted into ascending order"

added 199 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Selection sort javain Java

Hello I am working on a program in which 10000 random no repeat numbers are selectively sorted into ascending order.

I have written the following code.:

import java.util.Random;


public class Sorting {
    public static void main (String[] args){
        //Here, we initiate an array with the integers
        //1 through 10,000 in order.
        Random rgen = new Random();
        int[] intArray = new int[10000];
        for (int i=0; i<10000; i++) {
            intArray[i] = i+1;
        }
        //Here, we randomize the positions.
        for (int i=0; i<10000; i++) {
            int randomPosition = rgen.nextInt(10000);
            int temp = intArray[i];
            intArray[i] = intArray[randomPosition];
            intArray[randomPosition] = temp;
        }
        //Here, we check for the maximum in the 
        //unsorted section of the list.
        int max;
        for (int i=9999; i>=0; i--) {
            max = i;
            for (int j=i-1; j>=0; j--)
                if (intArray[j]>intArray[max]) {
                    max = j;
                }
            //Here, we swap the positions of the 
            //maximum and the last value in the 
            //unsorted section of the list.
            if (max != i) {
                int tmp = intArray[i];
                intArray[i] = intArray[max];
                intArray[max] = tmp;
            }
        }
        //Here, we output the result.
        for (int k=0; k<10000; k++) {
            System.out.println(intArray[k]);
        }
    }
}

I know I asked a similar question earlier, but I would appreciate any help.

Selection sort java

Hello I am working on a program in which 10000 random no repeat numbers are selectively sorted into ascending order.

I have written the following code.

import java.util.Random;


public class Sorting {
public static void main (String[] args){
//Here, we initiate an array with the integers
//1 through 10,000 in order.
    Random rgen = new Random();
    int[] intArray = new int[10000];
    for (int i=0; i<10000; i++) {
        intArray[i] = i+1;
    }
//Here, we randomize the positions.
    for (int i=0; i<10000; i++) {
        int randomPosition = rgen.nextInt(10000);
        int temp = intArray[i];
        intArray[i] = intArray[randomPosition];
        intArray[randomPosition] = temp;
}
//Here, we check for the maximum in the 
//unsorted section of the list.
    int max;
    for (int i=9999; i>=0; i--) {
        max = i;
        for (int j=i-1; j>=0; j--)
            if (intArray[j]>intArray[max]) {
                max = j;
            }
//Here, we swap the positions of the 
//maximum and the last value in the 
//unsorted section of the list.
        if (max != i) {
            int tmp = intArray[i];
            intArray[i] = intArray[max];
            intArray[max] = tmp;
        }
    }
//Here, we output the result.
    for (int k=0; k<10000; k++) {
        System.out.println(intArray[k]);
    }
}
}

I know I asked a similar question earlier but I would appreciate any help.

Selection sort in Java

I am working on a program in which 10000 random no repeat numbers are selectively sorted into ascending order.

I have written the following code:

import java.util.Random;


public class Sorting {
    public static void main (String[] args){
        //Here, we initiate an array with the integers
        //1 through 10,000 in order.
        Random rgen = new Random();
        int[] intArray = new int[10000];
        for (int i=0; i<10000; i++) {
            intArray[i] = i+1;
        }
        //Here, we randomize the positions.
        for (int i=0; i<10000; i++) {
            int randomPosition = rgen.nextInt(10000);
            int temp = intArray[i];
            intArray[i] = intArray[randomPosition];
            intArray[randomPosition] = temp;
        }
        //Here, we check for the maximum in the 
        //unsorted section of the list.
        int max;
        for (int i=9999; i>=0; i--) {
            max = i;
            for (int j=i-1; j>=0; j--)
                if (intArray[j]>intArray[max]) {
                    max = j;
                }
            //Here, we swap the positions of the 
            //maximum and the last value in the 
            //unsorted section of the list.
            if (max != i) {
                int tmp = intArray[i];
                intArray[i] = intArray[max];
                intArray[max] = tmp;
            }
        }
        //Here, we output the result.
        for (int k=0; k<10000; k++) {
            System.out.println(intArray[k]);
        }
    }
}

I know I asked a similar question earlier, but I would appreciate any help.

Post Merged (destination) from codereview.stackexchange.com/questions/25591/…
Added code block
Source Link
Guffa
  • 7k
  • 1
  • 22
  • 29

import java.util.Random;

public class Sorting { public static void main (String[] args){ //Here, we initiate an array with the integers //1 through 10,000 in order. Random rgen = new Random(); int[] intArray = new int[10000]; for (int i=0; i<10000; i++) { intArray[i] = i+1; } //Here, we randomize the positions. for (int i=0; i<10000; i++) { int randomPosition = rgen.nextInt(10000); int temp = intArray[i]; intArray[i] = intArray[randomPosition]; intArray[randomPosition] = temp; } //Here, we check for the maximum in the //unsorted section of the list. int max; for (int i=9999; i>=0; i--) { max = i; for (int j=i-1; j>=0; j--) if (intArray[j]>intArray[max]) { max = j; } //Here, we swap the positions of the //maximum and the last value in the //unsorted section of the list. if (max != i) { int tmp = intArray[i]; intArray[i] = intArray[max]; intArray[max] = tmp; } } //Here, we output the result. for (int k=0; k<10000; k++) { System.out.println(intArray[k]); } } }

import java.util.Random;


public class Sorting {
public static void main (String[] args){
//Here, we initiate an array with the integers
//1 through 10,000 in order.
    Random rgen = new Random();
    int[] intArray = new int[10000];
    for (int i=0; i<10000; i++) {
        intArray[i] = i+1;
    }
//Here, we randomize the positions.
    for (int i=0; i<10000; i++) {
        int randomPosition = rgen.nextInt(10000);
        int temp = intArray[i];
        intArray[i] = intArray[randomPosition];
        intArray[randomPosition] = temp;
}
//Here, we check for the maximum in the 
//unsorted section of the list.
    int max;
    for (int i=9999; i>=0; i--) {
        max = i;
        for (int j=i-1; j>=0; j--)
            if (intArray[j]>intArray[max]) {
                max = j;
            }
//Here, we swap the positions of the 
//maximum and the last value in the 
//unsorted section of the list.
        if (max != i) {
            int tmp = intArray[i];
            intArray[i] = intArray[max];
            intArray[max] = tmp;
        }
    }
//Here, we output the result.
    for (int k=0; k<10000; k++) {
        System.out.println(intArray[k]);
    }
}
}

import java.util.Random;

public class Sorting { public static void main (String[] args){ //Here, we initiate an array with the integers //1 through 10,000 in order. Random rgen = new Random(); int[] intArray = new int[10000]; for (int i=0; i<10000; i++) { intArray[i] = i+1; } //Here, we randomize the positions. for (int i=0; i<10000; i++) { int randomPosition = rgen.nextInt(10000); int temp = intArray[i]; intArray[i] = intArray[randomPosition]; intArray[randomPosition] = temp; } //Here, we check for the maximum in the //unsorted section of the list. int max; for (int i=9999; i>=0; i--) { max = i; for (int j=i-1; j>=0; j--) if (intArray[j]>intArray[max]) { max = j; } //Here, we swap the positions of the //maximum and the last value in the //unsorted section of the list. if (max != i) { int tmp = intArray[i]; intArray[i] = intArray[max]; intArray[max] = tmp; } } //Here, we output the result. for (int k=0; k<10000; k++) { System.out.println(intArray[k]); } } }

import java.util.Random;


public class Sorting {
public static void main (String[] args){
//Here, we initiate an array with the integers
//1 through 10,000 in order.
    Random rgen = new Random();
    int[] intArray = new int[10000];
    for (int i=0; i<10000; i++) {
        intArray[i] = i+1;
    }
//Here, we randomize the positions.
    for (int i=0; i<10000; i++) {
        int randomPosition = rgen.nextInt(10000);
        int temp = intArray[i];
        intArray[i] = intArray[randomPosition];
        intArray[randomPosition] = temp;
}
//Here, we check for the maximum in the 
//unsorted section of the list.
    int max;
    for (int i=9999; i>=0; i--) {
        max = i;
        for (int j=i-1; j>=0; j--)
            if (intArray[j]>intArray[max]) {
                max = j;
            }
//Here, we swap the positions of the 
//maximum and the last value in the 
//unsorted section of the list.
        if (max != i) {
            int tmp = intArray[i];
            intArray[i] = intArray[max];
            intArray[max] = tmp;
        }
    }
//Here, we output the result.
    for (int k=0; k<10000; k++) {
        System.out.println(intArray[k]);
    }
}
}
Source Link
Loading