Hallo Ich nehme eine High-School-Klasse und ich brauche Hilfe. Ich bekomme den Fehler im Titel erwähnt. hier ist mein Code (ich soll Zufallszahlen machen für die Menschen zu erraten, wo eine Null ist, und ich muss sie wissen lassen, wenn theyre es und wie nahe theyre schließen)inkompatible Typen: mögliche verlustreiche Konvertierung von Double zu Int (High School 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);
}
}
Welche Codezeile den Fehler verursacht? –
in der for-Schleife nums [i] = (int) 100 * Math.random(); – jacobOlivares123
Mögliches Duplikat von [Inkompatible Typen: mögliche verlustreiche Konvertierung von Double in Int] (http://stackoverflow.com/questions/29173575/incompatible-types-possible-lossy-conversion-from-double-to-int) –