[英]finding a number that would equalize a set of numbers through addition or subtraction
the user must input a set of numbers of type double that we must then find the number that equalizes the numbers 用户必须输入一组double类型的数字,然后我们必须找到等于这些数字的数字
here is a link to the question 这是问题的链接
https://www.dropbox.com/s/0hlps5r8anhjjd8/group.jpg https://www.dropbox.com/s/0hlps5r8anhjjd8/group.jpg
I tried to solve it myself, I did the basics, but for the actual solution I don't even know where to start ?_? 我尝试自己解决问题,我做了基础知识,但是对于实际的解决方案,我什至不知道从哪里开始? any hint would be much helpful 任何提示将很有帮助
Here my attempt: 这是我的尝试:
import java.util.Scanner;
public class test {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int arr =1000000;
while(arr > 10000) {
System.out.println("enter number of students that are providing the money");
arr = input.nextInt(); //user input for the size of the array
}
double size[] = new double[arr]; //array creation , size based on user input
for (int i =0; i<size.length;i++) { //to input values into the array
System.out.println("enter amount of money");
size[i] = input.nextDouble(); //input values into the array
}
for(int i=0; i<size.length;i++) { //prints out the array
System.out.println(size[i]);
}
}
}
Thank you in advance 先感谢您
Step 1. Read the data for a test case and put it into a suitable structure. 步骤1.读取测试用例的数据,并将其放入合适的结构中。 I would probably choose a double contribution[]
for this assignment. 我可能会为此任务选择double contribution[]
。
Step 2. Calculate the average contribution, avg. 步骤2.计算平均贡献avg。
Step 3. Sum up the amount of money that need to change hands. 步骤3.总结需要换手的金额。 sum over abs(contribution[i]-avg). 总和超过abs(contribution [i] -avg)。 Note: Don't forget to divide the total by 2. 注意:不要忘记将总数除以2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.