java - Can't print a Random integer -
i have started learning java. learning "randomization" "kilobolt" tutorials. when ran code:
import java.util.random; public class randomization { public static void main (string[] args) { random rand = new random(); rand.nextint(11); system.out.println(rand); } }
the console displayed:
java.util.random@1888759
is supposed happen? or there errors in code?
( sorry if used wrong terms in question, i'm new website)
you're printing reference object rand
. can either print out random number below:
public class randomization { public static void main (string[] args) { random rand = new random(); system.out.println(rand.nextint(11)); } }
or can store in int before printing:
public class randomization { public static void main (string[] args) { random rand = new random(); int randomnumber = rand.nextint(11); system.out.println(randomnumber); } }
either should work fine.
Comments
Post a Comment