Code:
public class budgePlan {
public static void main(String[] args) {
final int ROWS = 5;
final int COLS = 11;
int[][] budget = new int[6][12];
for (int i = 0; i < budget[0].length; i++) {
budget[0][i] = 500;
}
for (int i = 0; i < budget[1].length; i++) {
budget[1][i] = 200 + (int)(Math.random() * 201);
}
for (int i = 0; i < budget[2].length; i++) {
budget[2][i] = 100 + (int)(Math.random() * 101);
}
for (int i = 0; i < budget[3].length; i++) {
budget[3][i] = 300 + (int)(Math.random() * 201);
}
for (int i = 0; i < budget[4].length; i++) {
budget[4][i] = 125 + (int)(Math.random() * 151);
}
for (int i = 0; i < budget[5].length; i++) {
budget[5][i] = 150 + (int)(Math.random() * 251);
}
for (int i = 0; i <= ROWS; i++) {
for (int j = 0; j <= COLS; j++) {
System.out.print(" " + budget[i][j]);
}
System.out.println("");
}
System.out.print("\nThe total amount of money you need this year is: " + moneyNeeded(budget));
}
public static int[][] moneyNeeded(int[][] budget) {
int total = 0;
for (int row = 0; row < budget.length; row++) {
for (int column = 0; column < budget[row].length; column++) {
total += budget[row][column];
}
}
return budget;
}
}
Output:
500 500 500 500 500 500 500 500 500 500 500 500 347 245 330 384 210 210 365 247 239 346 252 336 115 159 153 134 151 187 132 126 101 124 141 121 405 437 408 354 497 434 413 344 426 301 373 430 154 275 217 239 213 228 150 137 187 151 260 250 375 387 254 203 342 383 332 289 207 180 368 259 The total amount of money you need this year is: [[I@56e5b723
Figured it out! Thanks all!

New Topic/Question
Reply



MultiQuote




|