18行報錯,真心不知道錯在哪里
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ??
? ? ? ? HelloWorld hello = new HelloWorld();
? ? ? ??
? ? ? ? int nums[] = {89, -23, 64, 91, 119, 52, 73};
? ? ? ??
? ? ? ? hello.sort(nums);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void sort(int[] nums){
? ? ? ? int scores[nums.length];
? ? ? ? int j = 0;
? ? ? ??
? ? ? ? for(int i = 0; i < num.length; i++){
? ? ? ? ? ? if((nums[i] < 0) | (nums[i] > 100))continue;
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? scores[j++] = nums[i];
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ? Arrays.sort(scores);
? ? ? ? System.out.println("考試成績前三名為\n"+scores[0]+"\n"+scores[1]+"\n"+scores[2]);
? ? }
? ??
}
2017-03-31
改成這個啊?
int[]?scores=new?int[nums.length];
2017-03-31
格式不對,你只是聲明了變量沒有分配空間給它。另外程序最后scores[]里面的數(shù)字改成 6 5 4 這三個。他的排序是升序的
2017-03-26
你的scores數(shù)組定義的格式不對