📚 知識家圖書館 奇摩知識+ 紀念館

JAVA高手請近來!!!

發問者 不了解 (Lv.2) ・2009 年 1 月 8 日 ・程式設計

題目如下 定義一個Exam類別, 屬性, 方法, 及主程式說明如下: • 屬性 A:資料型態為浮點數 B:資料型態為浮點數 • 方法 void SetA(float A): 設定A的值 void SetB(float B): 設定B的值 void Print (void): 列印A與B的值 • 主程式 – 宣稱Exam物件e1 – 設定e1的A與B值分別為10.0及20.0 – 列印e1的內容(呼叫e1的Print方法)

2 則回答

最佳解答
public class Exam { private float a; private float b; public static void main(String[] args) { Exam e1 = new Exam(); e1.setA(10.0f); e1.setB(20.0f); e1.print(); } public void setA(float a){ this.a = a; } public void setB(float b){ this.b = b; } public void print(){ System.out.println("A = " + a + " B = " + b); } } 希望這樣有幫到你 豚仔
安迪豬(Lv.6) 2009 年 1 月 8 日
public class Exam { private float A; private float B; public void setA(float A){ this.A=A; } public void setB(float B){ this.B=B; } public void Print(){ System.out.println(A); System.out.println(B); } public static void main(String[] args){ Exam e1=new Exam(); e1.setA((float)10.0); e1.setB((float)20.0); e1.Print(); } }
?(Lv.5) 2009 年 1 月 8 日

電腦與網際網路的其他問題