你好,我正在上高中班,我需要幫助。我收到標題中提到的錯誤。這裏是我的代碼(我應該做的隨機數供人猜,其中零是,我需要讓他們知道如果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) –