I have this homework assignment, where our teacher wants us to create the card game "War" in java. A huge part of it, is shuffling the 52 different cards into two players hands. I would greatly appreciate any help for when it comes to shuffling it. I am an inexperienced coder, and the other ones posted don't make any sense for me. My code:
package shuffle;
import java.util.Random;
public class SHUFFLE {
public static void main(String[] args) {
shuffle();
}
public static void shuffle() {
Random r = new Random();
int[] hand1 = new int[26];
int[] hand2 = new int[26];
int i = 1, rand, rand2;
int o = 1;
do {
System.out.println("Top");
rand = r.nextInt(52) + 1;
rand2 = r.nextInt(2) + 1;
System.out.println("number generated: "+rand);
System.out.println("sector: " + rand2);
if (rand2 == 1) {
if (rand <= 52) {
while (hand1[o] > 0) {
if (hand1[o] == rand) {
} else {
hand1[o]--;
}
}
while (hand2[i] > 0) {
if (hand2[i] == rand) {
} else {
hand2[i]--;
}
hand1[o] = rand;
o++;
}
}
}
if (rand2 == 2) {
if (rand <= 52) {
while (hand1[o] > 0) {
if (hand1[o] == rand) {
} else {
hand1[o]--;
}
}
while (hand2[i] > 0) {
if (hand2[i] == rand) {
} else {
hand2[i]--;
}
hand2[i] = rand;
i++;
}
}
}
}while(hand1[o] < 26 && hand2[i] < 26);
}
}