对于这个任务,我们需要让一个人输入人数和年数。然后程序从一个数组中获取随机数,然后给出一堆不同的信息。到目前为止,我设法做的是:
import java.util.Scanner; 导入 java.util.Random;
公共类实习工资{
/**
* @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);
}
}
}
这给出了一个人每年的平均收入,然后是他们的总收入。它仍然没有格式化,但我稍后会这样做。我想不通的是如何输出一个人每年赚了多少,这些数字加在一起得到一个人的总收入。任何帮助,将不胜感激