next()轉換類型調用時出錯怎么辦
import java.util.Arrays;
import java.util.Scanner;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ?Scanner read=new Scanner (System.in);
? ? ? ?int[] scores=new int[7];
? ? ? ?for( int m=0;m<scores.length;m++){
? ? ? ? ? scores[m]=read.nextInt();
? ? ? ? HelloWorld hello=new ?HelloWorld();
? ? ? ? ?System.out.println("考試成績的前三名為:");
? ? ? ? hello.arrays(scores);
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? ?public void arrays(int scores[]){
? ? ? ? ?int num=0;
? ? ? ? ?Arrays.sort(scores);
? ? ? ? ?for(int i = scores.length-1;i>=0&&num<3;i--){
? ? ? ? ? if(scores[i]>=0&&scores[i]<=100){
? ? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? ? num++;
? ? ? ? ? }
? ? ? ? ?
? ? ? ? ? continue;
? ? ? ? ??
? ? ? ? ??
? ? ? ? ?}
? ? ? ? ?
? ? ? ? ?
? ? ?}
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
2017-09-19
Arrays.sort();這個是用于對象數(shù)組按用戶自定義規(guī)則排序,意思是需要初始化
把Scanner刪了換成數(shù)組初始化
int []scores=new int []{89 , -23 , 64 , 91 , 119 , 52 , 73};
不是next()錯了