81.4k views
4 votes
Given that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.), write a statement that writes to standard output the element corresponding to October.

User Hetzbh
by
8.3k points

1 Answer

2 votes

Answer:

System.out.println(monthSales[9]);

Step-by-step explanation:

Since the array is called monthSales of type int and represents the months January - December, Its declaration in Java will be as follows:

int [] monthSales = new int[12];

This array contains 12 elements and it is indexed from 0-11 (i.e 0 for january and 11 for December)

The element corresponding to October which is the tenth month is at index 9

Hence the output statement System.out.println(monthSales[9]);

User Crispy
by
8.4k points