class Counter
{
 private static int number;
 private int m;
 public Counter()
 {
  m++;number++;
  System.out.println("This is NO."+number+" object,m="+m);
 }
}
public class Staticstics
{
 public static void main(String[] args)
 {
 
  for(int i=10;i<Math.random()*10;i++)
  new Counter();
}
}
程序编译、运行都没问题,可怎么看不到结果啊

解决方案 »

  1.   

    程序就没有进入for循环里面
    i永远都大于Math.random()*10
      

  2.   

    因为Math.random()是随机产出0到1之间的数字。你×10最大也就等于10 。而你的i=10所以,永远满足不了条件。
    new Counter(); 也就永远不会执行了
      

  3.   

    Math.random()生成的随机数范围是:[0,1) 即:大于等于0,小于1
    所以,上述代码中的循环条件一直是不成立的,故循环未执行...
      

  4.   

    试试
       i<(int)(Math.random()*10)
      

  5.   

    i永远都不小于Math.random()*10
    循环条件不成立
      

  6.   

    for循环的条件不成立,将
    for(int i=10;i <Math.random()*10;i++)
    改为:
    for(int i=0;i <Math.random()*10;i++)
      

  7.   

    for循环的条件不成立,将 
    for(int i=10;i <Math.random()*10;i++) 
    改为: 
    for(int i=0;i <10;i++)
    更简单,易于测试