Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不知道如何使这副牌洗牌 import java.util.*; 公开课洗牌 { 公共静态int-shuffleDeck(int[]组,int-theNumber) { int[]deck2=新int[26]; int[]deck3=新int[26]; 返回号码; } 公共静态void main(字符串[]args) { int[]甲板=新int[52]; 对于(int i=0;i_Java_Arrays_Sorting - Fatal编程技术网

不知道如何使这副牌洗牌 import java.util.*; 公开课洗牌 { 公共静态int-shuffleDeck(int[]组,int-theNumber) { int[]deck2=新int[26]; int[]deck3=新int[26]; 返回号码; } 公共静态void main(字符串[]args) { int[]甲板=新int[52]; 对于(int i=0;i

不知道如何使这副牌洗牌 import java.util.*; 公开课洗牌 { 公共静态int-shuffleDeck(int[]组,int-theNumber) { int[]deck2=新int[26]; int[]deck3=新int[26]; 返回号码; } 公共静态void main(字符串[]args) { int[]甲板=新int[52]; 对于(int i=0;i,java,arrays,sorting,Java,Arrays,Sorting,我不确定为什么要将数据组一分为二,但如果不需要,则可以使用Collections.shuffle(): 你是说一个充满甲板、甲板2和甲板3的阵列吗?为什么要将甲板一分为二?还不清楚这能达到什么效果…请看一个好的洗牌算法。是的,我正在尝试洗牌所有甲板你说的“所有甲板”是什么意思?当然你有一副52张卡片…但是,你还是从一个数组开始。你还没有解释为什么你要创建两个更小的数组开始…仅仅是写下代码可能对OP没有多大帮助。至少,在代码中加入注释,解释它如何对OP起作用。这会改进你的答案如果你包含描述OP代码

我不确定为什么要将数据组一分为二,但如果不需要,则可以使用
Collections.shuffle()


你是说一个充满甲板、甲板2和甲板3的阵列吗?为什么要将甲板一分为二?还不清楚这能达到什么效果…请看一个好的洗牌算法。是的,我正在尝试洗牌所有甲板你说的“所有甲板”是什么意思?当然你有一副52张卡片…但是,你还是从一个数组开始。你还没有解释为什么你要创建两个更小的数组开始…仅仅是写下代码可能对OP没有多大帮助。至少,在代码中加入注释,解释它如何对OP起作用。这会改进你的答案如果你包含描述OP代码为何无法工作的文本,那就更糟了。对不起,我教过你这是非常自我解释的,不再是正确的答案了?发生了什么,需要更多帮助吗?:)
import java.util.*;

public class shuffleDeck
{ 
  public static int shuffleDeck (int[] deck, int theNumber) 
  {
     int [] deck2 = new int [26];
     int [] deck3 = new int [26];
     return theNumber;
  }

  public static void main(String[] args)
  {
    int [] deck = new int [52];
    for(int i=0; i<52; i++)
    {
        deck[i]=i+1;
    }
    int count;
    count=1;
    int total=1;
    shuffleDeck(deck, count);
    System.out.println();
  }
}
// Create an array, fill it the way you want
Integer[] deck = new Integer[]{1, 2, 3, 4};

// Shuffle the elements in the array
Collections.shuffle(Arrays.asList(deck));
public static void shuffle(int[] deck) {
    // the random number generator used to shuffle the deck
    Random random = new Random();
    for (int i = deck.length, j, tmp; i > 1; i--) {
        // get a random position between 0 and i-1
        j = random.nextInt(i); 
        // swap the current position (i-1) with the random one ...
        tmp = deck[i - 1];
        deck[i - 1] = deck[j];
        deck[j] = tmp;
    }
}