Total members 11895 |It is currently Sun Dec 22, 2024 4:51 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





The program is basically taking 6 random numbers betweem 1 - 55
(RandPbNum[]) and comparing them to an array of arrays of the
PlayedPbNum[] numbers.

The problem is that I can't seem to get the RandPbNum[1] to compare to
the PlayedPbNums[1][1], looping through PlayedPbNums [1][2],[1][3]..
etc...
I have looked in many places for the answer and have tried coding it a
few different ways but I end up with a very laborious code that oesnt
bwork as I expect. There has to be a cleaner way than nesting if-else
statements on every element of the array?




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

Code:
int RandPbNum [] = ...;
int PlayedPbNum [][] = ...;
...
int i;
for (i = 0; i < 55; i++) {
if (RandPbNum [i] != PlayedPbNum [1][i]) {
break;
}
}
if (i == 55) {
System.out.println ("RandPbNum [] and PlayedPbNum [1][] are equal");
} else {
System.out.println ("RandPbNum [] and PlayedPbNum [1][] are unequal
at position " + i);
}


Of course, RandPbNum and PlayedPbNum could be a Vector and Vector [],
respectively, and you could use the native equals () comparison (which
does this code anyway). The downside to this is that you would have to
wrap everything in an Integer object. Messy. If I were you, I'd stick
with the above code.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : compare an array with another array?
 Array difference for associate array     -  
 Pad array to the specified length with a value     -  
 Array sort     -  
 Pop the element off the end of array     -  
 XML Document into an Array in php     -  
 Array C++ Class     -  
 Average of an array. Please help     -  
 PHP Array Functions     -  
 Array shuffle     -  
 Array Passing     -  



Topic Tags

Java Arrays
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com