New to Java! We have to create a "sales" 2D array and initialize it with 100.00. Then we have to up the 3rd quarter by 500.00 and then lower the 4th quarter by 50.00. I know there's something simple I'm missing, but I can't quite figure it out. Any help will be greatly appreciated! Thanks!

This is the code:

public class Array2D
{


   public static void main(String args[])
   {
		double sales[][] = new double[5][4] ;

   		for (int row = 0; row <sales.length; row++)
   		{
   			for (int column = 0; column < sales[row].length; column++)
   			{
   				sales[row][column] = 100.00 ;
				System.out.print(sales[row][column] + " ") ;
			}

		   				System.out.println();
   		}

		System.out.println("**************************") ;

		quarterThree(sales) ;
		quarterFour(sales) ;
   }


	public static void quarterThree(double sales[][])
	{

        for (int row = 0; row < sales.length; row++)
   		{
   			for (int column = 0; column < sales[row].length; column++)
   			{
				sales[row][2] = sales[row][2] + 500.00 ;
 				System.out.print(sales[row][column] + " ") ;

   			}

				System.out.println() ;
   		}

   		System.out.println("**************************") ;

	}

	public static void quarterFour(double sales[][])
	{

   		for (int row = 0; row < sales.length; row++)
   		{
  			for (int column = 0; column < sales[row].length; column++)
  			{
   				sales[row][3] = sales[row][3] - 50.00 ;
   				System.out.print(sales[row][column] + " ") ;
  			}

   			System.out.println() ;
   		}
	}

}//end class

And this is the output:

100.0 100.0 100.0 100.0
100.0 100.0 100.0 100.0
100.0 100.0 100.0 100.0
100.0 100.0 100.0 100.0
100.0 100.0 100.0 100.0
**************************
100.0 100.0 1600.0 100.0
100.0 100.0 1600.0 100.0
100.0 100.0 1600.0 100.0
100.0 100.0 1600.0 100.0
100.0 100.0 1600.0 100.0
**************************
100.0 100.0 2100.0 -100.0
100.0 100.0 2100.0 -100.0
100.0 100.0 2100.0 -100.0
100.0 100.0 2100.0 -100.0
100.0 100.0 2100.0 -100.0

for (int column = 0; column < sales[row].length; column++)
   			{
				sales[row][2] = sales[row][2] + 500.00 ;
 				System.out.print(sales[row][column] + " ") ;
 
   			}

Let row = 0.

I'm seeing sales[0][2] changing multiple times, 4 to be exact. I doubt you're doing that on purpose.

Thanks! I see it now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.