Ask Question
1 March, 13:37

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.

+3
Answers (1)
  1. 1 March, 15:29
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers