This example describes the Java simple array ordering (bubbling method). Share to everyone for your reference, specific 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]; Custom 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 array Sort 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 sort 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 help you with Java programming.