所以挑戰在於提示用戶輸入一個整數值「count」。接下來 提示他們輸入「count」更多的值。然後將輸入的每個值平方並將其添加到主值 值總和中。然後顯示輸入的所有數字的平方和。 的生成輸出的例子是這樣的:在java中進行平方和總計
Please enter an integer value: 3
Please enter 3 numeric values:
7 8 3.5
The sum of the squares of each of these numbers is: 125.25
我還是新學習的代碼,所以我在如何在單個用戶輸入方多個值有點失落,也合計起來。任何人都可以提供幫助嗎?
import java.util.Scanner;
public class Assign2 {
public static void main(String[] args) {
sum_squares();
}
public static void sum_squares(){
Scanner in = new Scanner(System.in);
System.out.println ("Please enter an integer value:");
int count = in.nextInt();
System.out.println ("Please enter" + count + "more values:");
int square = in.nextInt();
}
}
你能告訴你哪部分問題你不明白嗎?你可以**解決你的問題**? – 2014-10-19 22:46:44
說到在第二個提示中輸入的值的平方,然後總計這些平方值的結果。我失去了如何去做這件事。例如,在我發佈的示例中, 請輸入3個數值 7 8 3.5 每個在java中顯示的平均值的示例總是使用預編碼的int值,如 i = 0 int square = Math.pow(i ,2) 所以我失去了如何去做這個掃描器條目 – 2014-10-19 22:58:47
好吧,我會給你3個提示:你需要一個循環(像這樣:for(int i = 0; i
Tom
2014-10-19 23:03:44