package?com.HelloWorld;
import?java.util.Arrays;
public?class?HelloWorld?{
????
???? ?//完成?main?方法
????????public?static?void?main(String[]?args)?{
????????????HelloWorld?hello=new?HelloWorld();
????????????
????????????hello.sort(89?,?-23?,?64?,?91?,?119?,?52?,?73);
????????????
????????}
????????
????????//定義方法完成成績排序并輸出前三名的功能
????????public?void?sort(int?scores[]){
???????? Arrays.sort(scores);
???????? for(int?i=0;i<2;i++){
???????? System.out.println(scores[i]);
???????? if(scores[i]>100){
???????????? System.out.println("輸入無效");
???????????? }else?if(scores[i]<0){
???????????? System.out.println("輸入無效");
???????????? }
???????? }
????????
????????
????????}
????????這個在調(diào)試sort()的時候顯示紅色,為什么會不行呢?
2022-03-26
把代碼發(fā)的全一點(diǎn),看一下你的代碼邏輯老師的意思,應(yīng)該就是要讓我們練習(xí)這個<q>標(biāo)籤及瞭解它的語義.因為標(biāo)籤正確使用,有利排名搜尋.提供給您參考~
2015-12-09
我把System.out.pringtln("前三名的成績?yōu)椋?+hello.show());
變成
System.out.println("前三名的成績?yōu)椋?);
? ? ? ?hello.show(scores);
就可以了,為什么呢?
2015-12-09
System.out.pringtln("前三名的成績?yōu)椋?+hello.show());這個是你打的
2015-12-09
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("前三名的成績?yōu)椋?);
??????? hello.show(scores);
??????? }
??????? ?
??????? public void show(int []scores){
?????????? ?
??????????? Arrays.sort(scores);
?????????? ?
??????????? int num=0;
?????????? ?
??????????? for(int i=scores.length - 1;num<=3;i--){
?????????????? ?
??????????????? if(scores[i]>100 || scores[i]<0){
?????????????????? ?
??????????????? continue;
??????????? }
??????????????? num++;
?????????????? ?
??????????????? System.out.println(scores[i]);
??????????????? ?
?????????????? }
??? }
你那個show方法不能寫在println里面(你這都打錯真是無語),并且這個方法是有參數(shù)的,你的參數(shù)呢,先把前面幾章再認(rèn)真看看吧
2015-12-08
其實(shí)我寫的與題目偏了,這個程序表達(dá)的是 輸入89 , -23 , 64 , 91 , 119 , 52 , 73
然后自動輸出前三名。但是我也想知道這樣的程序應(yīng)該怎么弄。
我更改之后還是不行。
2015-12-08
public class HelloWorld {
??? ?
???????? //完成 main 方法
??????? public static void main(String[] args) {
?????????? ?
??????????? HelloWorld hello = new HelloWorld();
?????????? ?
???????????? int []scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};
??????????? ?
??????????? hello.sort(scores);
?????????? ?
??????? }
???????????? //定義方法完成成績排序并輸出前三名的功能
??????? public void sort(int []scores){
?????????? ?
??????????? Arrays.sort(scores);
??????????? int num = 0;
?????????? ?
??????????? for(int i = scores.length - 1; i >= 0 ; i--){
??????????????? if(scores[i] > 100 || scores[i] < 0){
??????????????????? continue;????
??????????????? }
?????????????? ?
??????????????? num ++;
??????????????? if (num > 3){
??????????????????? break;
??????????????? }
??????????????? System.out.println(scores[i]);
??????????? }??
??????? }
你那個有好幾個問題啊,改起來好麻煩,你先看看這個,不懂再說
2015-12-08
顯示紅色好像是代表sort是JAVA關(guān)鍵字吧 ?關(guān)鍵字不能拿來定義方法名
2015-12-08
public?void?sort(int?scores[])應(yīng)該是public?void?sort(int[]?scores)
hello.sort(89?,?-23?,?64?,?91?,?119?,?52?,?73);
應(yīng)該是int[] scores={89?,?-23?,?64?,?91?,?119?,?52?,?73};
hello.sort(scores);