8-1編程練習(xí),不知道怎么改,請(qǐng)大神幫忙看一下
最后那道編程練習(xí)題,方法的調(diào)用這里掌握的不是很好,提示錯(cuò)誤的地方不知道該怎么改,請(qǐng)問(wèn)一下,提示錯(cuò)誤的地方到底是什么原因出錯(cuò)了呢?
最后那道編程練習(xí)題,方法的調(diào)用這里掌握的不是很好,提示錯(cuò)誤的地方不知道該怎么改,請(qǐng)問(wèn)一下,提示錯(cuò)誤的地方到底是什么原因出錯(cuò)了呢?
2016-11-27
舉報(bào)
2016-11-27
? //完成 main 方法
??? public static void main(String[] args) {
int scores={89,-23,64,91,119,52,73};
System.out.println("考試成績(jī)的前三名為:");
new HelloWorld().top3(scores);
??? }
?? ?
??? //定義方法完成成績(jī)排序并輸出前三名的功能
?? ?
??? private void top3(int[] scores){ ?
??????? Arrays.sort(scores);
??????? for(int i=scores.length-1;i>=0;i--){
??????????? if(0<=scores[i]&&scores[i]<=100){
??????????? System.out.println(scores[i]);?? ?
??????????? }
??????? }
??? }
2016-11-27
?import java.util.Arrays;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ?int scores[]={89,-23,64,91,119,52,73};?
? ? ? ?System.out.println("考試成績(jī)前三名為:");
? ? ? HelloWorld hello=new HelloWorld();
? ? ? hello.getTop3(scores);
? ? }
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void getTop3(int scores[]){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? }
2016-11-27
? //完成 main 方法
??? public static void main(String[] args) {
int scores={89,-23,64,91,119,52,73};
System.out.println("考試成績(jī)的前三名為:");
new HelloWorld().top3(scores);
??? }
?? ?
??? //定義方法完成成績(jī)排序并輸出前三名的功能
?? ?
??? private void top3(int[] scores){ ?
??????? System.out.println(91);
??????? System.out.println(89);
??????? System.out.println(73);
??? }
這樣也能通過(guò)。。。。