java - 如何在 Java 中声明一个洗牌的方法?
问题描述
此方法旨在洗牌。当前方法声明具有“void”返回类型,并且在运行代码时出现错误“方法声明无效;需要返回类型”。可以改用什么返回类型?
public void shuffle()
{
int count = 0;
int index = 0;
for(int i; i = 100; i++)
{
count = (int)Math.Random() * 52;
index = (int)Math.Random() * 52;
DeckofCards[count] = DeckofCards[index];
DeckofCards[index] = DeckofCards[count];
}
}
解决方案
问题是for循环。您声明inti
但从不初始化。条件段当前是一个分配。您需要初始化并更改条件。
for (int i = 0; i < 100; i++) {
}
推荐阅读
- reactjs - 在 React Native 存储中上传图像时缺少参数“路径”
- kotlin - Kotlin 合约对另一个属性/功能的影响
- python - 如何更改字典的长度
- python - 在 Python 中将整数数组转换为二进制代码数组
- c# - 为什么我的 C# 代码没有正确中断?
- php - 如何通过 .htaccess 重定向所有 POST 请求?
- laravel - 上传图片时出现 Froala 405(不允许的方法) - Laravel
- oracle - 查找最受欢迎的汽车数量和租车总数
- android - 将一个android studio项目推送到GitHub上某个组织仓库的指定目录下
- javascript - 如何将 jquery 插件导入我的 React 组件?转js