函數與引數
一、函數設定
public static 傳回值型態 函數名稱 (型態 引數1, 型態 引數2,...)
{
程式敘述; // 函數主體
return 運算式; // 函數主體
}public static 傳回值型態 函數名稱 ()
{
程式敘述; // 函數主體
}public class ch07_1 {
public static void main(String[] args)
{
star(); //呼叫star函數
System.out.println("使用函數印星星");
star(); //呼叫star函數
}
public static void star() //star函數
{
for(int i=0; i<20; i++)
System.out.print("*");
System.out.print("\n");
}二、引數資料型態
三、傳遞多個引數
四、函數傳值(pass by value)
Last updated