2009年6月1日 星期一

"Lab Array"

Study Display 6.1, and then write a program that can sort numbers in ascending order.


-----
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
double[] score = new double[5];
int index;
double max, temp;
System.out.println("Enter 5 Scores");
score[0] = keyboard.nextDouble();
max = score[0];
for(index = 1; index <>
score[index] = keyboard.nextDouble();
for( index = score.length-1; index >-1 ; --index){
for (int j = 0; j <>
if(score[index] > score[j]){
temp = score[j];
score[j] = score[index];
score[index] = temp;
}
}
}
System.out.println("The scores are" );
for(index = 0; index<>
System.out.println(score[index]);
}

沒有留言:

張貼留言