為什么要用帶參無(wú)返回值的方法
不用帶參數(shù)的也可以完成啊,直接寫(xiě)就行了啊。帶參無(wú)返回值,帶參有返回值,具體這四個(gè)有什么用途呢。
這樣寫(xiě)不也可以嗎
import java.util.Arrays;
public class lastTest {
public static void main(String[] args) {
int [] scores = ?{ 89, -23, 64, 91, 119, 52, 73 } ;
Arrays.sort (scores);
? ?System.out.println("考試成績(jī)前三名");
? ?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 ;
?}
?else {
?System.out.println(scores [i]);}
?}?
?}
??
? ? }
2019-05-23
這樣寫(xiě)沒(méi)錯(cuò),但是main函數(shù)中不適合寫(xiě)太多語(yǔ)句,你應(yīng)該定義方法,在main函數(shù)中調(diào)用方法就行了