我想創建一個程序,用戶輸入的整數從最大到最小排序。此外,我需要找到一種方法來打印最大和最小數字。當我定義了值的時候,代碼很好的排序,但是現在我已經把它切換到用戶輸入了,因爲某些原因它發回了「0」。這是我的代碼用戶輸入數組
import java.util.Scanner;
public class SortInteger {
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please input three numbers");
int num = input.nextInt();
int number [] = new int [num]; //Sorting Array
int temp;
boolean correct = false; // Forces the sorting to continue till the numbers are in order
while(correct ==false){
correct = true;
for(int i = 0; i>number.length-1; i++){
if(number [i] > number [i+1]){
temp = number [i+1];
number [i+1] = number[i];
number[i]= temp;
correct = false;
}
}
}
for(int i = 0; i<number.length-1; i++){ //outputs the array to user
System.out.println(number[i]);
}
}
}
'i> number.length-1; '應該是'我
2013-02-20 17:33:06