public class Matrix {
public static void main(String[] args) {
// TODO Auto-generated method stub
int width = (int) (Math.random() * 50 )+(int)(Math.random() * 2);
//[0,50)即[0,49] + [0,2)即[0,1] == [0,50]
int height =(int)(Math.random() * 100 )+(int)(Math.random() *2);
//[0,100)即[0,99] + [0,2)即[0,1] == [0,100]
if(width %2 ==0)
{
width *= -1;
}
if(height %2 == 0)
{
height *= -1;
}
//制造负数伪随机,奇偶机率各半,对应矩形长宽。
System.out.println("The point is : ("+ height +","+width+")");
}
}
Java语言程序设计(基础篇)第十版 编程练习题 3.16(随机点)
最新推荐文章于 2022-06-14 00:06:16 发布