第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

求大神指導(dǎo)下哪里出錯(cuò)了,為什么運(yùn)行有問題

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};

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

hello.show(nums);

}

public void show(int[] nums){

Arrays.sort(nums);

int sum=0;

for(int i=nums.length;i>=0;i--){

if(nums[i]<0||nums[i]>100){

continue;

}

sum++;

if(sum>3){

break;

}

System.out.println(nums[i]);

}

}

} ? ? ?

運(yùn)行結(jié)果:

考試成績(jī)的前三名為
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at HelloWorld.show(HelloWorld.java:15)
at HelloWorld.main(HelloWorld.java:9)

正在回答

3 回答

循環(huán)從nums.length-1開始

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

戲劇人生3188129 提問者

噢噢,是的,謝謝啦
2016-05-30 回復(fù) 有任何疑惑可以回復(fù)我~

for(int i=nums.length;i>=0;i--)數(shù)組越界了。應(yīng)該為:for(int i=nums.length-1;i>=0;i--)

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

package com.imooc;

import java.util.Scanner;

/*

?* 功能:為指定的成績(jī)加分,直到分?jǐn)?shù)大于等于60為止

?* 輸出加分前的成績(jī)和加分后的成績(jī),并且統(tǒng)計(jì)加分的次數(shù)

?* 步驟:

?* 1.定義一個(gè)變量,用來統(tǒng)計(jì)加分的次數(shù)

?* 2.使用循環(huán)為成績(jī)加分

?* 3.每次執(zhí)行循環(huán)時(shí)加1分,并且統(tǒng)計(jì)加分的次數(shù)

?*?

?* 使用Scanner工具類來獲取用戶輸入的值

?* Scanner類位于java.util包中,使用時(shí)需要導(dǎo)入此包

?* 步驟:

?* 1.導(dǎo)入java.util.Scanner

?* 2.創(chuàng)建Scanner對(duì)象

?* 3.接收并保存用戶輸入的值

?*/

public class Demo01 {

public static void main(String[] args){

Scanner input=new Scanner(System.in); //創(chuàng)建Scanner對(duì)象

//print和println區(qū)別:println輸出信息后會(huì)換行,而print不會(huì)換行

System.out.println("請(qǐng)輸入您的考試成績(jī):");

int score=input.nextInt(); //獲取成績(jī)信息并保存在變量score中

int count=0; ?//統(tǒng)計(jì)次數(shù)

System.out.println("加分前的成績(jī):"+score);

while(score<60){

score++;//每次循環(huán)加1分

count++;//統(tǒng)計(jì)加分的次數(shù)

}

System.out.println("加分后的成績(jī):"+score);

System.out.println("共加了"+count+"次!");

}

}


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

jinjin71

bad
2016-05-30 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

求大神指導(dǎo)下哪里出錯(cuò)了,為什么運(yùn)行有問題

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

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

幫助反饋 APP下載

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

公眾號(hào)

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