標題:
物件導向基礎概念 (四)
[打印本頁]
作者:
tonyh
時間:
2013-8-24 16:24
標題:
物件導向基礎概念 (四)
public class ch74 //主類別
{
public static void main(String args[]) //主函式 (主方法)
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y)); //將變數代入MyMath類別中的pow()函式
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath //自訂MyMath類別, 並宣告該類別中的三個方法 (函式)
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
作者:
t2364705
時間:
2013-8-24 16:32
public class ch74
{
public static void main(String args[])
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
作者:
黃博鴻
時間:
2013-8-24 16:33
public class ch74
{
public static void main(String args[])
{
int x=2,y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath
{
public static float pow(int a,int b)
{
int result=1;
for(int i=0; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a,int b)
{
return a-b;
}
public static int plus(int a,int b)
{
return a+b;
}
}
複製代碼
作者:
蔡昀佑
時間:
2013-8-24 16:36
public class ch74 //主類別
{
public static void main(String args[]) //主函式 (主方法)
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y)); //將變數代入MyMath類別中的pow()函式
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath //自訂MyMath類別, 並宣告該類別中的三個方法 (函式)
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
作者:
劉漢文
時間:
2013-8-24 16:43
public class ch74
{
public static void main(String args[])
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
作者:
尤泓鈞
時間:
2013-8-24 16:48
public class ch74
{
public static void main(String args[])
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}
public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
作者:
t3742238
時間:
2013-9-6 20:53
public class ch74
{
public static void main(String args[])
{
int x=2, y=5;
System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
}
}
class MyMath
{
public static float pow(int a, int b)
{
int result=1;
for(int i=1; i<=b; i++)
result=result*a;
return result;
}public static int minus(int a, int b)
{
return a-b;
}
public static int plus(int a, int b)
{
return a+b;
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2