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);
????}
????//定義方法完成成績(jī)排序并輸出前三名的功能
????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;?
????}
}
2016-05-16
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.showTop(scores);
??? }
?? ?
??? public void showTop(int[] scores){
??????? // 定義方法完成成績(jī)排序并輸出前三名的功能
??????? 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]);
?????????? ?
??????? }
??? }
}
2016-05-11
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];
?? ???? }
}
最簡(jiǎn)單方法,考慮下這種方法
2016-05-10
12行public ?還有為什么不輸出可能是你If else哪里的語(yǔ)法問(wèn)題
2016-05-07