java矩阵加法_在java中的数组加法?
我到目前為止有一個程序要求用戶選擇一些元素。該程序然后要求用戶選擇數量由元素數量指示的次數。我將如何使用數組以及while或for循環找到這組數字的方差。我在高中時沒有什么特別的感覺。下面是我當前的代碼:在java中的數組加法?
//write an app that finds the variance of a set of numbers
class temp1 {
public static void main(String args[])
{
int counter = 0;
String question;
question = "How many elements do you want?: ";
EasyReader console = new EasyReader();
System.out.println(question);
int answer;
int answer2;
answer = console.readInt();
int[] numbers = new int[answer];
int mean;
System.out.println();
while(true)
{
System.out.println("Please enter a number: ");
answer2 = console.readInt();
counter++;
if(counter==answer)
{
break;
}
}
mean = (numbers[0]+numbers[1]+numbers[2]+numbers[answer])/answer;
System.out.print(mean);
}
}
+1
您使用循環遍歷的方差的應用元素并計算它。檢查你的筆記,了解如何使用循環以及如何計算差異,然后使用Java對它進行編程。 –
+0
我知道如何找到差異,這只是我不明白數組。我不知道如何添加數組的內容。我會用循環嗎? –
+0
瀏覽[本教程](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/array.html)。 –
總結
以上是生活随笔為你收集整理的java矩阵加法_在java中的数组加法?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java dateformat hh_J
- 下一篇: java axis webservice