Ask Question

Assume that a Money variable yearlySales has also been declared. Write the necessary code that traverses the monthlySales array and adds it all up and stores the resulting total in yearlySales. Be sure make sure that yearlySales ends up with a valid value, i. e. a value of cents that is less than 100.

+1
Answers (1)
  1. 29 December, 20:47
    0
    public class num3 {

    public static void main (String[] args) {

    double yearlySales = 0;

    int [] monthlySales = new int[12];

    for (int i = 0; i
    yearlySales = yearlySales + = monthlySales[i];

    }

    }

    }

    Explanation:

    Declare the variable yearlySales and initialize to 0.

    Create an Array of ints monthlySales, set its length to 12

    Using a for loop, add up all the elements in array and store in the varible yearly sales.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume that a Money variable yearlySales has also been declared. Write the necessary code that traverses the monthlySales array and adds it ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers