我一直在試圖完成這個Java項目,併爲了我的生活,我無法讓它運行,我一直在想我的大腦。下面是我應該做的事:初學者的Java - 需要使用Eclipse的幫助
編寫調用每一個從下面的列表Math類的方法,並提供輸出顯示的方法調用,發送到方法值的程序,返回結果。每個列出的方法都會告訴您使用哪些值。例如:
列出的方法:
double pow(double a, double b):
使用2.0
和3.0
。您的程序將顯示:Math.pow(2.0, 3.0) = 8.0
。當調用接受雙精度的方法時,即使它爲零,也應使用至少有一位十進制數字的數字,如上例所示。請記住帶小數的數字是雙字。嘗試使用會產生易於驗證的結果的值。下面的列表:
double pow(double a, double b): Use 3.0 and 2.0 double sqrt(double x): Use 25.0 int max(int a, int b): Use 6 and 2 double max(double a, double b): Use -50.0 and 7.0 static double random()
示例輸出:
Math.pow(3.0, 2.0) = 9.0 Math.sqrt(25.0)=5.0 Math.max(6,2)=6 Math.max(-50.0,7.0)=7.0 Math.random()= -random value-
測試你與所示的值的程序示例,修復任何錯誤。
向程序中添加一個名爲randomStudy的方法,該方法沒有參數並且不返回任何值。在此方法中,執行以下操作:
a。聲明三個int變量:total,min和max。將總數設置爲0,最小值爲11,最大值爲-1。
b。創建一個將運行1000次的循環。在循環體中,生成一個介於1和10之間的隨機int值。將此數字添加到您的總數。如果此數字小於最小值,則用新數字更新最小值。如果它大於最大值,則用新數字更新最大值。
c。循環後,顯示以下內容:
Min value: x Max value: y Average: z
用您的最小值和最大值替換x和y。計算z的總數除以1000d。
從主要方法調用您的新randomStudy方法。
突出顯示並複製Eclipse中顯示的輸出。將輸出粘貼到源代碼文件的底部。在文本結果上方添加文本結果,然後註釋掉剛剛打開的文本以及輸出文本。您的評論結果應該是這個樣子:
/* Results: Math.pow(3.0, 2.0)= 9.0 Math.sqrt(25.0) = 5.0 Math.max(6, 2) = 6 Math.max(-50.0, 7.0) = 7.0 Math.random() = -random number- Min value: 1 Max value: 10 Average: 5.553 */
public class Method {
public void main(String[] args) {
public static double pow(double 3.0, double 2.0);
public static double sqrt(double 25);
public static int max(int 6, int 2);
public static double max(double -50, double 7)
public static double random()
}
}
public class randomStudy{
public void main(String[] args) {
int min = 11;
int max = -1;
int total = 0;
int i;
for(i = 0; i < 1000; i++){
int randomInt = (int)(11.0 * Math.random());
System.out.println("Random integer between 1 and 10 : " + randomInt);
int newtotal = (randomInt + int total);
if int newtotal < int min {
int min = Math.random());
}
else{
System.out.println("int min");
}
if int newtotal > max {
int max = Math.random());
}
else{
System.out.println("int max");
}
}
System.out.println("Min value:" + int min);
System.out.println("Max Value:" + int max);
System.out.println("Average:"+ int newtotal/1000d);
}
}
我得到這個錯誤
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method pow(double, double) is undefined for the type Math
The method pow(double, double) is undefined for the type Math
at Math.main(Math.java:3)
這是徹頭徹尾的題外話,完全不理什麼程序員是** [講述](http://programmers.stackexchange.com/tour) **:http://meta.stackexchange.com/a/129632/165773 – gnat
我建議你閱讀[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug -small-programs /) – Doval
我建議你閱讀教科書的第二和第三章。你並沒有真正走上正軌。 – Evorlor