ERROR: This method must return a result of type int

前端 未结 5 1656
耶瑟儿~
耶瑟儿~ 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:34

    Its because you have declared return type as int and you have given return statment inside for loop now think what will happen if your code dont go in for loop than there will be no return statement so,

    so make your code like

    public static int shuffleDeck (int[] deck, int theNumber)
      {
     int [] array1 = new int [52];    
        Random random = new Random();
        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;
        }
       return 0;
    }
    

提交回复
热议问题