i wrote a simple html file that prints 10 random numbers using javascript. javascript object in turn uses java.util.Random class (live connect) to output the result! but i am not getting exact output when using with functions and events like onLoad or onclick!
<html> <body onLoad="hello()"> <script language="javascript"> function hello() { var i=0;for(;i<10;i++)
{ var j=new java.util.Random(i); document.writeln(j); } } </script></body></html>
And i can get output if we dont use function!
开发者_如何学JAVA<html> <body > <script language="javascript"> var i=0;for(;i<10;i++)
{ var j=new java.util.Random(i); document.writeln(j); } </script></body></html>
can anybody help me with this bug!
Use this:
var j=Math.random()*i;
instead of var j=new java.util.Random(i);
Perhaps this is the correct syntax?
for(;i<10;i++){
Random r = new Random();
int j = r.nextInt(i)
document.writeln(j);
}
精彩评论