当前位置: 技术问答>java相关
请问Math.random()不能默认调用么
来源: 互联网 发布时间:2015-11-07
本文导语: 请问Math.random()不能随意调用么,需要 import java.math.*;之类的语句么. 1.相关语句: int blockType; int turnState; blockType=(int)(Math.random()*1000)%7; turnState=(int)(Math.random()*1000)%4; 2.编译报错信息: --------------------Configuration: j2sdk1.4....
请问Math.random()不能随意调用么,需要
import java.math.*;之类的语句么.
1.相关语句:
int blockType;
int turnState;
blockType=(int)(Math.random()*1000)%7;
turnState=(int)(Math.random()*1000)%4;
2.编译报错信息:
--------------------Configuration: j2sdk1.4.0 --------------------
D:JCreatorProMyProjectsGo.java:191: cannot resolve symbol
symbol : method random ()
location: class Math
blockType=(int)(Math.random()*1000)%7;
^
D:JCreatorProMyProjectsGo.java:192: cannot resolve symbol
symbol : method random ()
location: class Math
turnState=(int)(Math.random()*1000)%4;
^
2 errors
Process completed.
请问我该怎么解决???
import java.math.*;之类的语句么.
1.相关语句:
int blockType;
int turnState;
blockType=(int)(Math.random()*1000)%7;
turnState=(int)(Math.random()*1000)%4;
2.编译报错信息:
--------------------Configuration: j2sdk1.4.0 --------------------
D:JCreatorProMyProjectsGo.java:191: cannot resolve symbol
symbol : method random ()
location: class Math
blockType=(int)(Math.random()*1000)%7;
^
D:JCreatorProMyProjectsGo.java:192: cannot resolve symbol
symbol : method random ()
location: class Math
turnState=(int)(Math.random()*1000)%4;
^
2 errors
Process completed.
请问我该怎么解决???
|
不用 import java.lang.Math
这是我的测试,编译运行都没问题
public class Test{
public static void main(String[] a){
int blockType;
int turnState;
blockType=(int)(Math.random()*1000)%7;
System.out.println(blockType);
turnState=(int)(Math.random()*1000)%4;
System.out.println(turnState);
}
}
这是我的测试,编译运行都没问题
public class Test{
public static void main(String[] a){
int blockType;
int turnState;
blockType=(int)(Math.random()*1000)%7;
System.out.println(blockType);
turnState=(int)(Math.random()*1000)%4;
System.out.println(turnState);
}
}
|
java.lang下的包该是自动加载的-----------绝对没错.
你的错误不是对java.lang.Math的用法产生怀疑,而是对你写的random()方法不能解析.也许是上下文的问题.或是写的地方不对.
你的错误不是对java.lang.Math的用法产生怀疑,而是对你写的random()方法不能解析.也许是上下文的问题.或是写的地方不对.