Sudhir Srinivasan wrote:Whereas my objective is to print them as
...
Could the problem be...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
R. Jain wrote:The code that assigns the prime number to your 2-D array is inside the nested for-loop for iterating the array...
If your :-
is inside your loop: -
You will get the same value for all the cells..
R. Jain wrote:
*PS: - Your one method isPrime() is doing so many of task..
1). It is iterating over the array,
2). It is finding which number are primes among them,
3). plus it is creating new 2D array for those prime numbers
4). Finally it is printing the array..
Ideally a single method should do a single job...
Try to separate your task this way.. Life would be comparatively easy..
R. Jain wrote:Did you read my last post in this topic?? I think I have stated the problem with your code there..
Still, I'll try to help you again..
Sudhir Srinivasan wrote:
One method to determine whether the number is a prime(from the array of primes and non-primes)
Sudhir Srinivasan wrote:
So, ended up combining the lot and net result
Winston Gutkowski wrote:
Sudhir Srinivasan wrote:Whereas my objective is to print them as
...
Could the problem be...
So I guess the next question is:
Do you want to know how to convert a simple array to a matrix, or do you simply want to print it out like one?
Winston
Winston Gutkowski wrote:
Actually, the basic problem is that you don't need to convert the array in order to print it out the way you want. So I guess the next question is:
Do you want to know how to convert a simple array to a matrix, or do you simply want to print it out like one?
Winston Gutkowski wrote:
BTW, could you please edit your post to remove all those enormous lines? It makes your Thread very hard to read; and it's also bad coding practise.
I'd do it for you, but there are tons of them.
I suggest you re-read the UseCodeTags (←click) page. Thoroughly.
Winston
Apologoies accepted (). I am afraid reposting does not enhance readability, and reposting different code inside quote tags simply causes confusion. People expect what is in quote tags to be exactly what was posted before.Sudhir Srinivasan wrote: . . . Sorry. I've trimmed the same and posted again. Hope this enhances the readability for other forum members.
Thanks,
Sudhir
R. Jain wrote:
You should call your isPrimeNum() method with only one argument (i.e. the number itself which your checking for Prime)..
R. Jain wrote:
R. Jain wrote:
Still, I'll try to help you again..
---
---
Now, try to simplify your approach (Preferably, reduce the level of nesting you have for that loop)..
Try to come up with some modification, then see how it works..
Sudhir Srinivasan wrote:
Winston Gutkowski wrote:
Actually, the basic problem is that you don't need to convert the array in order to print it out the way you want. So I guess the next question is:
Do you want to know how to convert a simple array to a matrix, or do you simply want to print it out like one?
It would be of great help if you could explain both concepts.
Sudhir Srinivasan wrote:
0 1 2 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
where, as you're aware, the nos. 0,1,9,15......etc. to name a few are not primes
Campbell Ritchie wrote:Have you come across the Sieve of Eratosthenes for finding prime numbers?
Sudhir Srinivasan wrote:
R. Jain wrote:
What exactly is happening here: - For each cell, you are iterating over the 1D array, and assigning the last prime
number to that cell (So, the same value 97).
arrayPrime[(x * row) + y] = arrayPrime[i];
array2d[x][y] = arrayPrime[(x * row) + y]; /* This is the PROBLEM */ /* It should not be inside your innermost for loop.. */
Now, try to simplify your approach (Preferably, reduce the level of nesting you have for that loop)..
Try to come up with some modification, then see how it works..
I'm working on modifying the problem area as suggested and get back to you once resolved.......
A "dutch baby" is not a baby. But this tiny ad is baby sized:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|