大佬大佬大佬教教我啊
import java.util.Arrays;
public class HelloWorld {
//完成 main 方法
public static void main(String[] args) {
int[] scores=new int[]{89,-23,64,91,119,52,73};
HelloWorld hello=new HelloWorld();
Arrays.sort(scores);
int[] result=hello.calcScore(scores);
System.out.println("考试成绩的前三名为:");
for(int i=0;i<result.length;i++){
System.out.println(result[i]);
}
}
//定义方法完成成绩排序并输出前三名的功能
public int[] calcScore(int[] scores){
int[] tempArray=new int[3];
int num=0;
for(int i=scores.length-1;i>=0;i--){
if(scores[i]<0||scores[i]>100){
continue;
}else{
num+=1;
if(num>3){
break;
}else{
for(int j=0;j<tempArray.length;j++){
if(tempArray[j]==0){
tempArray[j]=scores[i];
break;
}
}
}
}
}
return tempArray;
}
public static void main(String[] args) {
// show( x , y)值传递,因为返回的是int,可以用int类型接收这个结果
int sum = show(10, 20);
// 打印结果
System.out.println(sum);
}
/**
* 返回值类型 int
* 参数 int x, int y
*/
public static int show(int x, int y){
int z = x + y;
// 将 x + y 结果返回
return z;
}public class Test {
public static void main(String[] args) {
// show( x , y)值传递,因为返回的是int,可以用int类型接收这个结果
int sum = show(10, 20);
// 打印结果
System.out.println(sum);
}
/**
* 返回值类型 int
* 参数 int x, int y
*/
public static int show(int x, int y){
int z = x + y;
// 将 x + y 结果返回
return z;
}
}在方法名前定义返回类型,方法中写关键字return + 该类型的参数结果。
你可用简单理解为,别人问你一个什么结果,你在这个方法中给出这个结果就好了。