So how do you guys study programming exactly?
I'm learning through a book, and I got the basics down. Then I came across a problem asking me to create a method in Java that shuffles cards, using the method Math.random().
the answer was this:
Now that I've seen it, I can understand how this method shuffles a deck of cards.
In fact, this method was mentioned really early in the book.
However, it would have taken me forever to write the method unless I had memorized it.
Judging by the contents of the book, it seems that the writer assumes that you have the math skills to write that method without looking at the answer sheet. This, I don't have.
In the future, will I come across situations where I have to write methods like this often? Is math absolutely necessary?
I really should start studying math, shouldn't I? lol
I'm learning through a book, and I got the basics down. Then I came across a problem asking me to create a method in Java that shuffles cards, using the method Math.random().
the answer was this:
void shuffle() {
for(int x=0; x< cards.length*2;x++) {
int i = (int)(Math.random()*cards.length);
int j = (int)(Math.random()*cards.length);
SutdaCard tmp = cards;
cards = cards[j];
Now that I've seen it, I can understand how this method shuffles a deck of cards.
In fact, this method was mentioned really early in the book.
However, it would have taken me forever to write the method unless I had memorized it.
Judging by the contents of the book, it seems that the writer assumes that you have the math skills to write that method without looking at the answer sheet. This, I don't have.
In the future, will I come across situations where I have to write methods like this often? Is math absolutely necessary?
I really should start studying math, shouldn't I? lol






