0
对于此作业,我们需要请求一个人输入人数和年数。然后程序从数组中获得随机数,然后给出一堆不同的信息。我设法做到目前为止是这样的:
import java.util.Scanner; import java.util.Random;从随机生成的数组中打印出单个值
公共类InternSalary {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner (System.in);
Random myRandom = new Random();
int value = myRandom.nextInt(19000) + 1000;
int years = 0;
int people = 0;
int total = 0;
int average = 0;
System.out.println("Enter number of people for which you have salary information");
people = s.nextInt();
System.out.println("Enter number of years for which you have salary information");
years = s.nextInt();
int [][] salaries = new int [people][years];
for (int i=0; i<people; i++) {
for (int j=0; j <years; j++)
salaries[i][j] = myRandom.nextInt (19000)+1000;
}
for (int i = 0; i < people; i++) {
total = 0;
for(int j = 0; j < years; j++) {
total += salaries[i][j];
}
System.out.println(total/years);
System.out.println(total);
}
}
}
这使平均每年做一个人,然后他们提出的总。它还没有格式化,但我会稍后再做。我无法弄清楚的是如何输出一个人每个年度的个人收入,这些数字加起来就是一个人的总收入。任何帮助,将不胜感激
非常感谢。它现在完美运行!我仍然需要格式化它,使它看起来像一张桌子,但是我保存它以备后用。 – user2120893 2013-03-03 21:44:59