0
can somone please give me the code to this question, user enters and stores the average monthly rainfall....
figures (int) for three (3) towns over a year. The rows represent the months, and the columns represent the towns. PLEASE I NEED CODE IN JAVA ASAP.
5 Respuestas
+ 2
Write program where user enters and stores the average monthly rainfall figures (int) for three (3) towns over a year. The rows represent the months, and the columns represent the towns.
+ 1
You are gonna need a two dimensional array.. Your array needs 12 lines (rows) for storing months (0 is January, 1 is February etc) and 3 columns, each column represents a city (0 is city1, 1 is city 2...)
So you need int [] [] rainfall = new int [12] [3];
This array is where the user will store the info of the rainfall. The array should contain the following info - - >
rainfall[0][0] = (rainfall of January of City1),
rainfall[2][1] = (rainfall of March of City2) etc
You need to ask the user to input data to populate the array. One example is the following:
for (int i=0; i<12; i++){
System.out.println("Enter rainfall of January") ;
// Read the input of the user on 3 variables for example
rainfall[i][0] = first_value;
rainfall[i][1] = second_value;
rainfall[i][2] = third_value;
}
After that is done ask fpr an int input from the user and print that row. Use a switch for that like this
switch(user_input) {
Case 0: //January, print rainfall[0][i]...
// print 3 totals by adding the numbers in each row
break;
Case 1: // February.......
}
0
Calculate and print the total rainfall figures for each town, and the average rainfall for each month. Use a switch statement to print out the month name according to the column subscript value (E.g. if col = 0, then print January, col = 1 then print February, etc.) with the corresponding total alongside it.
0
That’s the whole question please help.
0
Thank you so much