我刚刚开始学习,写了个程序,但是在jdk中不能运行,提示找不到方法random方法,但是在别人相同的jdk下能运行,我重装jdk后还是一样的结果。另外这个程序在eclipse下不能编译,提示“syntax error,'for each' statements are only available iif the source level 5.0”(我的jdk是6.0,eclipse是3.2),在别人机子上却没有问题。希望得到大侠的指点。
程序代码如下:
import java.util.*;
public class LotterDrawing
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("How many numbers do you want to draw");
int k=in.nextInt();
System.out.println("What is the highest number you can draw");
int n=in.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
{
a[i]=i+1;
}
int[] b=new int[k];
for(int i=0;i<k;i++)
{
int r=(int)(Math.random() *n);
b[i]=a[r];
a[r]=a[n-1];
n--;
}
Arrays.sort(b);
for(int p:b)
System.out.println(p);
}
}