Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Computing Arrays...

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Computing Arrays...

    I'm having some real problems with the last bit of the programming. I have to use a nested loop to add the up the amounts in each row (which I did). Then, the program has to add up all of the row totals and store it for another calculation. When that's completed, I have to use two, non-nested for loops. One loop has to compute the percentage of each columns contribution to the over all total that was "stored".

    Here's what I've got.
    public class SalesAnalysis
    {
    	public static void main(String[] args)
    	{
    		int salesTable[][] = new int [6][5];
    		int column, row;
     
    		salesTable[0][0] = 750;
    		salesTable[1][0] = 800;
    		salesTable[2][0] = 700;
    		salesTable[3][0] = 850;
    		salesTable[4][0] = 900;
     
    		salesTable[0][1] = 660;
    		salesTable[1][1] = 700;
    		salesTable[2][1] = 600;
    		salesTable[3][1] = 800;
    		salesTable[4][1] = 800;
     
    		salesTable[0][2] = 910;
    		salesTable[1][2] = 950;
    		salesTable[2][2] = 750;
    		salesTable[3][2] = 1000;
    		salesTable[4][2] = 960;
     
    		salesTable[0][3] = 800;
    		salesTable[1][3] = 900;
    		salesTable[2][3] = 600;
    		salesTable[3][3] = 950;
    		salesTable[4][3] = 980;
     
     
    		for(row = 0; row < 5; row++)
    		{
    			for(column = 0; column < 4; column++)
    		{   salesTable[row][4] += salesTable[row][column];
    		}
     
    			System.out.println("Department " + (row + 1) + " total sales " + salesTable[row][4]);
    		}
     
    				System.out.println("");
    		for(column = 0; column < 4; column++)
    		{
     
    			for(row = 0; row < 5; row++)
    				{salesTable[5][column] += salesTable[row][column];}
    			System.out.println("Quarter " + (column + 1) + " total sales " + salesTable[5][column]);
    					}
     
    							System.out.println("");
    					for(column = 0; column < 4; column++)
    		{
     
    		}
    	}
    }


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Computing Arrays...

    I'm having some real problems with the last bit of the programming. I have to use a nested loop to add the up the amounts in each row (which I did). Then, the program has to add up all of the row totals and store it for another calculation. When that's completed, I have to use two, non-nested for loops. One loop has to compute the percentage of each columns contribution to the over all total that was "stored".
    What do you want from us ?

    How can we help you ?
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

Similar Threads

  1. Grid Computing, need to understand and learn
    By madcrazyboys in forum The Cafe
    Replies: 1
    Last Post: December 21st, 2010, 11:32 PM
  2. arrays
    By dwamalwa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2010, 01:44 AM
  3. Something wrong with computing the average
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 18th, 2010, 08:51 AM
  4. project on mobile computing
    By seejay in forum Java Theory & Questions
    Replies: 2
    Last Post: May 18th, 2010, 03:31 AM
  5. Why output is displaying 0 for calculation in java?
    By tazjaime in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 26th, 2009, 02:18 PM

Tags for this Thread