java - 无法从数组中选择一个元素并将其分配给矩阵中的一个点
问题描述
我正在尝试从数组中选择一个元素并将其分配给矩阵中的一个点,但是每次我尝试它时都会发送此错误消息错误:不兼容的类型:可能有损从双精度转换为整数
public CountLetters(int rows, int cols, String[] vals)
{
char matrix[][] = new char[rows][cols];
char[] source = {'a','b','c','d','e','f','g'};
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++){
matrix[i][j] = (int)source[Math.floor(Math.random()*source.length)];
}
}
}
解决方案
尝试这个
public void countLetters(int rows, int cols)
{
char matrix[][] = new char[rows][cols];
char[] source = {'a','b','c','d','e','f','g'};
for(int i = 0; i < cols; i++){
for(int j = 0; j < rows; j++){
matrix[i][j] = source[(int)Math.floor(Math.random()*source.length)];
}
}
}
推荐阅读
- mysql - 我们如何在sql中获得同一列的最高2个值和最低2个值
- influxdb - 如何更有效地从 influxDB 获取最后一个值
- javascript - 没有从 Promises 收到正确的数据?
- openedge - 为什么会话崩溃后 Progress 会返回初始屏幕?
- dynamics-crm - 多个帐户/联系人可以在 Microsoft Dynamics 365 中共享客户地址吗
- go - Go中的接口实现强制
- hibernate - 休眠中的固有抽象类
- android - 后退按钮没有返回到 android java 中的先前活动
- jquery - 这种类型的 Id 的 Jquery 选择器?
- xcode - Flutter Xcode 无法在模拟器 arm64 错误上构建应用程序