publicclassSort{privatestaticintNUMBER_OF_ELEMENTS=10;privatestaticdouble[]string1=newdouble[NUMBER_OF_ELEMENTS];Sort(){}Sort(intnewNUMBER_OF_ELEMENTS,double[]x){NUMBER_O...
public class Sort{
private static int NUMBER_OF_ELEMENTS = 10;
private static double[] string1 = new double[NUMBER_OF_ELEMENTS];
Sort(){
}
Sort(int newNUMBER_OF_ELEMENTS, double[] x){
NUMBER_OF_ELEMENTS = newNUMBER_OF_ELEMENTS;
string1 = x;
}
public static double[] sortProcess(){
for(int i = 0; i < NUMBER_OF_ELEMENTS; i++){
if(string1[i] > string1[i + 1]){
double j = string1[i];
string1[i] = string1[i + 1];
string1[i + 1] = j;
}
}
return string1;
}
public static void main(String[] args){
double[] numbers = new double[5];
double[] newNumbers = new double[5];
numbers[0] = 3;
numbers[1] = 6;
numbers[2] = 8;
numbers[3] = 4;
numbers[4] = 1;
Sort sort1 = new Sort(5,numbers);
newNumbers = sort1.sortProcess();
System.out.println("The smallest number is"+newNumbers[0]);
}
}
展开