java - incompatible types: possible lossy conversion from double to int (high school hw) -
hello taking high school class , need help. getting error mentioned in title. here code (i supposed make random numbers people guess 0 , need let them know if theyre close , how close theyre)
import javax.swing.joptionpane; public class p5g { public static void main(string[] arg) { string width = joptionpane.showinputdialog("how many rows want?"); string length = joptionpane.showinputdialog("how many columns 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 =0; < nums.length; i++) { nums[i]=(int)100*math.random(); } string row = joptionpane.showinputdialog("choose row"); string col = joptionpane.showinputdialog("choose column"); int ro = integer.parseint( row ); int co = integer.parseint( col ); } }
the math.random
return double
so rather casting int
try
new double (100*math.random()).intvalue ();
Comments
Post a Comment