package shuji.java1;
import java.util.*;
public class Lottery {
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
System.out.println("How many?");
int k=in.nextInt();
System.out.println("What is?");
int n=in.nextInt();
int [] numbers= new int[n];
for (int i = 0; i < numbers.length; i++) {
numbers=i+1;
}
int [] result=new int[k];
for (int i = 0; i < result.length; i++) {
int r=(int) (Math.random()*n);
result=numbers[r];
numbers[r]=numbers[n-1];
n--;
}
Arrays.sort(result);
System.out.println("better");
for(int r:result)
System.out.println(r);
}
}
最后两行for(int r:result)
System.out.println(r);
的for(int r:result)理解为for(int r=0;r<result.length;r++)
那System.out.println(r);怎么理解?
|
|