q求大神指點(diǎn),真的看不出那錯(cuò)了,謝謝
我的代碼運(yùn)行成功但是輸出錯(cuò)誤,輸出的只有73.
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? int scores[]={89,-23,64,91,119,52,73};
? ? HelloWorld hello = new HelloWorld();
? ? System.out.println("考試前三名的成績(jī)是:");
? ? hello.sort(scores);//調(diào)用方法
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void sort (int [] arr){
? ? ? ? for(int i=1;i<arr.length;i++){
? ? ? ? ? ? for(int j=0;j<arr.length-i;j++){
? ? ? ? ? ? ? ? if(arr[j+1]>arr[j]){
? ? ? ? ? ? ? ? ? ? int tmp=arr[j];
? ? ? ? ? ? ? ? ? ? arr[j]=arr[j+1];
? ? ? ? ? ? ? ? ? ? arr[j+1]=tmp;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }//冒泡排序
? ? ? ? int count=0;
? ? ? ? Loop:for(int i=0;i<arr.length-1;i++){
? ? ? ? ? ? if(arr[i]<=100&&arr[i]>=0){
? ? ? ? ? ? ? ? count++;
? ? ? ? ? ? ? ? System.out.println(arr[i]);//符合條件count+1,且輸出
? ? ? ? ? ? ? ?if(count==3){
? ? ? ? ? ? ? ? ? ? break Loop;//超過三名跳出循環(huán)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? }
? ? ? ??
? ? ? ??
? ? }
}
2019-01-07
public class HelloWorld {
?public static void main(String[] args) {
??? int scores[]={89,-23,64,91,119,52,73};
??? HelloWorld hello = new HelloWorld();
??? System.out.println("考試前三名的成績(jī)是:");
??? hello.sort(scores);//調(diào)用方法
???????
??? }
???
??? //定義方法完成成績(jī)排序并輸出前三名的功能
??? public void sort (int[] arr){
??????? for(int i=1;i<arr.length;i++){
??????????? for(int j=0;j<arr.length-i;j++){
??????????????? if(arr[j+1]>arr[j]){
??????????????????? int tmp=arr[j];
??????????????????? arr[j]=arr[j+1];
??????????????????? arr[j+1]=tmp;
??????????????? }
??????????? }
??????? }//冒泡排序
??????? int count=0;
??????? Loop:for(int i=0;i<arr.length-1;i++){
??????????? if(arr[i]<=100&&arr[i]>=0){
??????????????? count++;
??????????????? System.out.println(arr[i]);//符合條件count+1,且輸出
?????????????? if(count==3){
??????????????????? break Loop;//超過三名跳出循環(huán)
??????????????? }
??????????? }
???????????
??????? }
???????
???????
??? }
}
可以輸出的,里面有些打成中文的了
2019-01-07
小哥哥,你的這個(gè)呢:import java.util.Arrays;
2019-01-05
我知道哪里錯(cuò)了,謝謝