Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- int[] myArray = {8, 5, 10, 5, 2, 9, 7, 0, 7, 10, 2, 7, 9, 3, 9, 7, 5, 10, 0, 9, 3, 5, 4, 8};
- int[] myArray1 = {15, 99, 21, 27, 33, 34, 65, 75, 58, 85, 69, 49};
- int[] myArray2 = {66, 22, 11, 11, 11, 11, 11, 0, 1, 5, 6, 7, 8, 1, 2, 3, 3, 2, 11};
- System.out.println("My array = " + Arrays.toString(myArray));
- thirdSortingArray(myArray);
- System.out.println("My new array = " + Arrays.toString(myArray) + "\n");
- System.out.println("My array1 = " + Arrays.toString(myArray1));
- secondSortingArray(myArray1);
- System.out.println("My new array1 = " + Arrays.toString(myArray1) + "\n");
- System.out.println("My array2 = " + Arrays.toString(myArray2));
- sortingArary(myArray2);
- System.out.println("My new array2 = " + Arrays.toString(myArray2) + "\n");
- }
- public static void sortingArary(int[] myArray) {
- for (int i = 0; i < myArray.length; i++) {
- for (int j = 0; j < myArray.length - 1; j++) {
- if (myArray[j] > myArray[j + 1]) {
- int temp = myArray[j];
- myArray[j] = myArray[j + 1];
- myArray[j + 1] = temp;
- }
- }
- }
- }
- public static void secondSortingArray(int[] myArray) {
- for (int j = 0; j < myArray.length; j++) {
- int temp = j;
- for (int i = j; i < myArray.length; i++) {
- if (myArray[i] < myArray[temp]) {
- temp = i;
- }
- }
- int temp2 = myArray[j];
- myArray[j] = myArray[temp];
- myArray[temp] = temp2;
- // System.out.println(Arrays.toString(myArray));
- }
- }
- public static void thirdSortingArray(int[] myArray) {
- for (int i = 1; i < myArray.length; i++) {
- for (int j = i; j > 0; j--) {
- if (myArray[j - 1] > myArray[j]) {
- int temp = myArray[j];
- myArray[j] = myArray[j - 1];
- myArray[j - 1] = temp;
- }
- }
- // System.out.println(Arrays.toString(myArray));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement