Difference between revisions of "Equating Two Arrays"

From CompSciWiki
Jump to: navigation, search
Line 1: Line 1:
 
{{1010PrAD|ProblemName=Equating Two Arrays
 
{{1010PrAD|ProblemName=Equating Two Arrays
  
|Problem= This problem envolves you seeing if two hard coded arrays are equal. You should use two int arrays to equate. Even though your arrays are hard coded into your program, you should not assume to know the length of the arrays. In other words use: <pre> array.length</pre> Remember that your arrays start indexing at 0 and that you should watch out for loops indexing arrays out of bounds. These are the most common pitfalls with a problem like this. If you can try to structure your code so that your loop is only comparing to the length of one of the arrays and not both of them.  
+
|Problem= This problem envolves you seeing if two hard coded arrays are equal. You should use two int arrays to equate. Even though your arrays are hard coded into your program, you should not assume to know the length of the arrays. In other words use: <pre> array.length</pre> Remember that your arrays start indexing at 0 and that you should watch out for loops indexing arrays out of bounds. These are the most common pitfalls with a problem like this. If you can try to structure your code so that your loop is only comparing to the length of one of the arrays and not both of them. Print out whether your arrays are equal or not to the console using <pre>System.out.println ();</pre>
  
 
|SideSectionTitle=...By Students
 
|SideSectionTitle=...By Students

Revision as of 09:41, 8 April 2010

Back to the Program-A-Day homepage

Problem

This problem envolves you seeing if two hard coded arrays are equal. You should use two int arrays to equate. Even though your arrays are hard coded into your program, you should not assume to know the length of the arrays. In other words use:
 array.length
Remember that your arrays start indexing at 0 and that you should watch out for loops indexing arrays out of bounds. These are the most common pitfalls with a problem like this. If you can try to structure your code so that your loop is only comparing to the length of one of the arrays and not both of them. Print out whether your arrays are equal or not to the console using
System.out.println ();
 

...By Students

Solution

The solution...

Code

Solution Code

Back to the Program-A-Day homepage