The example in this article describes Java's simple array sorting (bubble method). Share it with everyone for your reference, the details are as follows:
import java.util.Scanner; public class testArray { public static void main(String[] args) { Scanner input = new Scanner(System.in); int Max=0; int[] score = new int[5]; / /Customize the array length System.out.println("please input five numbers:"); for(int i=0; i< score.length; i++){ score[i] = input.nextInt(); } for(int j=0; j<score.length-1; j++){ swap(score); //Call the array sorting method} System.out.println("########## the result : ###########"); for(int i=0; i<score.length; i++){ System.out.print(score[i]+"/t"); } } public static void swap(int[] arr){ //Bubble sorting for(int i=0; i<arr.length-1; i++){ if(arr[i]>arr[i+1]){ int temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } } }}
I hope this article will be helpful to everyone in Java programming.