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