this is a simple program that takes calculates gross sales and determines how many people have earned salary in ranges ( 200 to 299, 300 to 399, so on..) i have stored the values in an array ( counter) how do i use an enhanced for loop to print my array ( not counter controlled, only enhanced)
this is my program
public class Sales
{
public static void main(String args[])
{
//declare
double salesData[] = {750, 1200, 5000, 7575, 10000, 9250, 12500, 3560, 4800};
double gross = 0;//[] = new double[9];
int counter[]= new int[9];
int i=0;
//walk through sales data
for(i=0; i<salesData.length;i++)
{
//calculate gross
gross = 200 + salesData[i] * .09;
//determine range and increment count array
if((gross >200) && (gross <= 299))
counter[0] ++;
else if((gross >300) && (gross <= 399))
counter[1] ++;
else if((gross >400) && (gross <= 499))
counter[2] ++;
else if((gross >500) && (gross <= 599))
counter[3] ++;
else if((gross >600) && (gross <= 699))
counter[4] ++;
else if((gross >700) && (gross <= 799))
counter[5] ++;
else if((gross >800) && (gross <= 899))
counter[6] ++;
else if((gross >900) && (gross <= 999))
counter[7] ++;
else if (gross >1000)
counter[8]++;
//print gross
System.out.println(gross);
}
ifs:int indexToUpdate = (int)((gross - 200) / 100);Also, you currently skip over anything that lands on the hundred exactly. Is that intentional?