JAVA easy random for loop

  1. package firstjava;
  2. import java.util.Scanner;
  3. public class Forloop {
  4.     public static void main(String[] args) {
  5.     java.util.Scanner input = new java.util.Scanner(System.in);
  6.     int i;
  7.     int[] mylist = new int[10];
  8.     for ( i=0 ; i<mylist.length ; i++ ){
  9.         mylist[i] = (int)(Math.random()*100);
  10.         System.out.println( mylist[i] + " " );
  11.     }
  12.     }
  13. }


mistake you may make:
     on line 10.   (intMath.random()*100
先做前面double變成0
output:


留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year