最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

求大神指點(diǎn),謝謝!有一個(gè)錯(cuò)誤提示,一直搞不懂?。?!

package com.imooc;

import java.util.Arrays;

public class HelloWorld {? ?

? ? //完成 main 方法

? ? public static void main(String[] args) {

? ? ? ? HelloWorld hello=new HelloWorld();

? ? ? ? int[] scores={89,-23,64,91,119,52,73};

? ? ? ? hello.showTop(scores);

? ??}

? ? //定義方法完成成績(jī)排序并輸出前三名的功能

? ? ?public void showTop(int[] ?scores){

? ? ? ? Arrays.sort(scores);

? ? ? ? ?int i;

? ? ? ? ?for (i=scores.length-1;i>=0; i--) {

? ? ? ? ? ? ?if(scores[i]<=100&&scores[i]>=0){

? ? ? ? ? ? ? ? ?continue;

? ? ? ? ? ? ?}

? ? ? ? System.out.println("考試成績(jī)的前三名為:");

? ? ? ? System.out.println(scores[i]);

? ? ? ? System.out.println(scores[i-1]);

? ? ? ? System.out.println(scores[i-2]);

? ?} }}

這是運(yùn)行的錯(cuò)誤提示,請(qǐng)大神指點(diǎn)指點(diǎn),具體錯(cuò)在哪兒了!??!

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1

at com.imooc.HelloWorld.showTop(HelloWorld.java:26)

at com.imooc.HelloWorld.main(HelloWorld.java:9)


正在回答

2 回答

倒數(shù)第二行和倒數(shù)第三行數(shù)組越界了,這個(gè)時(shí)候i是等于0 的


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

櫻桃小wa子 提問者

哦,謝謝大哥,拿那這個(gè)要怎么改動(dòng)呢!
2015-06-11 回復(fù) 有任何疑惑可以回復(fù)我~

package com.imooc;

import java.util.Arrays;

public class HelloWorld { ??

? ? //完成 main 方法

? ? public static void main(String[] args) {

? ? ? ? HelloWorld hello=new HelloWorld();

? ? ? ? int[] scores={89,-23,64,91,119,52,73};

? ? ? ??

? ? ? ? hello.showTop(scores);

? ? }

? ? //定義方法完成成績(jī)排序并輸出前三名的功能

? ? ?public void showTop(int[] ?scores){

? ? Arrays.sort(scores);

? ? ? ? ?int i;

? ? ? ? ?for (i=scores.length-1;i>0; i--) {

? ? ? ? ? ? ?if(scores[i]<=100&&scores[i]>=0){

? ? ? ? ? ? ? ? ?continue;

? ? ? ? ? ? ?}

? ? ? ? System.out.println("考試成績(jī)的前三名為:");

? ? ? ? System.out.println(scores[i]);

? ? ? ? System.out.println(scores[i-1]);

? ? ? ? System.out.println(scores[i-2]);

? ?} }}

/*提示的錯(cuò)誤是數(shù)組下標(biāo)越界

?for (i=scores.length-1;i>0; i--) {}

*/

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

櫻桃小wa子 提問者

哦,謝謝大哥,那這個(gè)要怎么改動(dòng)呢!
2015-06-11 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

求大神指點(diǎn),謝謝!有一個(gè)錯(cuò)誤提示,一直搞不懂?。?!

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)