你好,我正在上高中班,我需要帮助。我收到标题中提到的错误。这里是我的代码(我应该做的随机数供人猜,其中零是,我需要让他们知道如果theyre接近它,以及如何接近更有耐力)不相容的类型:从double到int(高中hw)可能的有损转换
import javax.swing.JOptionPane;
public class p5g
{
public static void main(String[] arg)
{
String width = JOptionPane.showInputDialog("How many rows do you want?");
String length = JOptionPane.showInputDialog("How many columns do you want?");
int lol = Integer.parseInt(width);
int wow = Integer.parseInt(length);
int[][]gameBoard = new int[lol][wow];
int[] nums = new int[lol*wow];
for(int i =0; i < nums.length; i++)
{
nums[i]=(int)100*Math.random();
}
String row = JOptionPane.showInputDialog("Choose a row");
String col = JOptionPane.showInputDialog("Choose a column");
int ro = Integer.parseInt(row);
int co = Integer.parseInt(col);
}
}
什么行代码导致错误? for循环中的 –
nums [i] =(int)100 * Math.random(); – jacobOlivares123
[不兼容类型:可能有损从双精度转换为int]的可能重复(http://stackoverflow.com/questions/29173575/incompatible-types-possible-lossy-conversion-from-double-to-int) –