比卡丘0
2016-05-07 10:49
package imooc;
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int[] scores= {89,-23,64,91,119,52,73};
HelloWorld hello=new HelloWorld();
int[] good=hello.top3(scores);
}
//定义方法完成成绩排序并输出前三名的功能
pubic int[] top3(int[] scores){
Arrays.sort(scores);
int[] good=new int [3];
for(int i=scores.length-1;i>scores.length-3;i--){
if (scores[i]<100);
if(scores[i]>0);
else continue;
int j=0;
good[j]=scores[i];
j++;
System.out.println(good[j]);
}
return good;
}
}

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("考试成绩的前三名为:");
HelloWorld hello = new HelloWorld();
hello.showTop(scores);
}
public void showTop(int[] scores){
// 定义方法完成成绩排序并输出前三名的功能
Arrays.sort(scores);
int sum = 0 ;
for(int i = scores.length - 1 ; i >= 0 ; i --){
if(scores[i] < 0 || scores[i] > 100){
continue;
}
sum ++ ;
if( sum > 3 ){
break;
}
System.out.println(scores[i]);
}
}
}
package com.doe;
import java.util.Arrays;
public class Hello {
public static void main(String[] args) {
int[] scores={89,-23,64,91,119,52,73};
Hello hello=new Hello();
String info=hello.show(scores);
System.out.println(info);
}
public String show(int[] scores){
Arrays.sort(scores);
return "第一名是"+scores[scores.length-1]+"第二名是"+scores[scores.length-2]+"第三名是"+scores
[scores.length-3];
}
}
最简单方法,考虑下这种方法
12行public 还有为什么不输出可能是你If else哪里的语法问题
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int[] scores ={89,-23,64,91,119,52,73};
HelloWorld hello=new HelloWorld();
int count =hello.sort(scores);
System.out.println("前三名的数量为:"+count);
}
//定义方法完成成绩排序并输出前三名的功能
public int sort(int[] scores){
int count=0;
Arrays.sort(scores);
for(int i=scores.length-1;i>=0;i--){
if(count==3){
break;
}
if(scores[i]<=100&&scores[i]>=0){
System.out.println(scores[i]);
count++;
}
else
continue;
}
return count;
}
}Java入门第一季(IDEA工具)
1168236 学习 · 18754 问题
相似问题