troubleshooting Question

How do I populate Java arrays?

Avatar of aspnet-scotland
aspnet-scotlandFlag for United Kingdom of Great Britain and Northern Ireland asked on
8 Comments1 Solution331 ViewsLast Modified:

I am trying to understand the below code snippets. Can an experts expand upon these code snippets to help me understand how they can be populated and used in a real world example? They are helper methods to get me started writting a lottery program where the user can select up to 20 bets (one bet is a set of six numbers) for a random lottery draw.

private static void printAllBets(int [] [] allBets, int NUMBER_OF_BETS, int BET_SIZE) 
        //use nested for loop to print all bets
        for(int outer = 0; outer < NUMBER_OF_BETS ; outer++) 
            for(int inner = 0; inner < BET_SIZE ; inner++) 
                System.out.println(outer +" " +inner +"\n");
            }//end inner loop
        }//end outer loop
    private static void addBet(int [] [] allBets, int [] newBet, int row) 
        //add newBet to allBets at row
        for (int loop = 0;  loop < newBet.length;  loop++) 
            allBets[row][loop] = newBet [loop];
        }//end for loop
    }// end addBet
    private static int[] getBet(int [] [] allBets, int row) 
        //get six integers from row
        int [] temp;
        for (int loop = 0; loop < row; loop++)
            //store in array
            temp [loop] = allBets [row] [loop];
            // return array
            return temp;
    }//end method getBet

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros