ERROR: This method must return a result of type int

前端 未结 5 1702
耶瑟儿~
耶瑟儿~ 2021-01-25 03:51

Code:

import java.util.*;

public class shuffleDeck
{ 
    public static int shuffleDeck (int[] deck, int theNumber)
    {
        int [] array1         


        
5条回答
  •  梦谈多话
    2021-01-25 04:25

    Uppercase the name of your class to distinguish between class and method:

    public class ShuffleDeck {
    ...
    

    Perhaps it is even better to rename the method:

    public static int doTheShuffle(int[] deck, int theNumber) {
    

    If you want the function to return something sensible put the return out of the loop:

    for (int i = deck.length, j, tmp; i > 1; i--) {
        j = random.nextInt(i);
    
        tmp = deck[i - 1];
        deck[i - 1] = deck[j];
        deck[j] = tmp;
    }
    
    return theNumber;
    

    But all of this will only make the compiler not complain about syntax errors. Your algorithm still has bugs.

提交回复
热议问题