public class HelloWorld{? ? public static void main(String[] args){? ? ? ? //創(chuàng)建一個(gè)對(duì)象? ? ? ? HelloWorld hello = new HelloWorld();? ? ? ? //調(diào)用方法,傳入兩門(mén)課程的成績(jī)? ? ? ? hello.calcAvg(94,81);? ? }? ??? ? //自定義一個(gè)方法,以接受對(duì)象傳過(guò)來(lái)的數(shù)值? ? public void calcAvg(int a,int b){? ? ? ? double avg = (a + b)/2.0;? ? ? ? System.out.println("平均分:"+avg);? ? }
定義方法時(shí)的疑問(wèn)???public void calcAvg為什么不能寫(xiě)成public double calcAvg呢?不是有返回值嗎?
我腦袋挨踢了3343099
2016-05-13 19:07:52