需要生成01,02,03,04,05,06,07,08,09,10,11.的随机数。请指教

解决方案 »

  1.   

    Random random = new Random();
    random.nextInt(10);
    random = random + 1;
      

  2.   

     public static void main(String[] ar){
      int charIndex = (int) Math.floor(Math.random() * 11);
      System.out.print(charIndex);
     
      }
      

  3.   

    //这个可能更好些
      public static void main(String[] ar){
      //
      List<String> list = getList();
      int charIndex = (int) Math.floor(Math.random() * 10);
      System.out.print(list.get(charIndex));
     
      }
    public static List<String> getList() { List<String> list = new ArrayList<String>();
    list.add("01");
    list.add("02");
    list.add("03");
    list.add("04");
    list.add("05");
    list.add("06");
    list.add("07");
    list.add("08");
    list.add("09");
    list.add("10");
    list.add("11");
    return list;
    }
      

  4.   

    受2楼启迪,想起来了,是:
     (int)(Math.random()*11+1);
     Math.random()  是[0,1),包括左边界。 谢了。