無法輸出結(jié)果,求大家?guī)兔纯矗?/h1>
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? int stuc[]={89,-23,64,91,119,52,73}; ? ?
? ? //創(chuàng)建對象 ? ?
? ? HelloWorld shuchu=new HelloWorld(); ? ?
? ? //調(diào)用main方法,傳入數(shù)組參數(shù) ? ?
? ? shuchu.print(stuc);?
? ? System.out.println("前三名的成績?yōu)椋?);
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void print (int [] stuc)
? ? {
? ? ? ? Arrays.sort(stuc);
? ? ? ? int num=0;
? ? ? ? for(int i=1;i>7&&num<3;i++)
? ? ? ? {
? ? ? ? ? ? if(stuc[stuc.length-i]>=0&&stuc[stuc.length-i]<=100)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? num++;
? ? ? ? ? ? ? ? System.out.println(stuc[stuc.length-i]);
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? }
? ??
? ? }
??
}
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? int stuc[]={89,-23,64,91,119,52,73}; ? ?
? ? //創(chuàng)建對象 ? ?
? ? HelloWorld shuchu=new HelloWorld(); ? ?
? ? //調(diào)用main方法,傳入數(shù)組參數(shù) ? ?
? ? shuchu.print(stuc);?
? ? System.out.println("前三名的成績?yōu)椋?);
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void print (int [] stuc)
? ? {
? ? ? ? Arrays.sort(stuc);
? ? ? ? int num=0;
? ? ? ? for(int i=1;i>7&&num<3;i++)
? ? ? ? {
? ? ? ? ? ? if(stuc[stuc.length-i]>=0&&stuc[stuc.length-i]<=100)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? num++;
? ? ? ? ? ? ? ? System.out.println(stuc[stuc.length-i]);
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? }
? ??
? ? }
??
}
2018-09-06
for(int i=1;i>7&&num<3;i++)中i>7改為i<7