一个JAVA程序 解释下 for(int r:result) 这个是什么意思?详细讲讲 谢·
importjava.util.*;publicclasslotterydrawing{publicstaticvoidmain(String[]args){Scanne...
import java.util.*; public class lotterydrawing { public static void main(String[] args) { Scanner in =new Scanner(System.in); System.out.print("How many numbers do you need to draw?"); int k = in.nextInt(); System.out.print("What is the highest nimber you can draw?"); int n = in.nextInt(); int[]numbers = new int[n]; for(int i=0;i<numbers.length;i++) numbers[i]=i+1; int[]result = new int[k]; for(int i=0;i<result.length;i++) { int r = (int)(Math.random()*n); result[i] = numbers[r]; numbers[r]=numbers[n-1]; n--; } Arrays.sort(result); System.out.println("Bet the following combination. It'll make you rich!"); for(int r:result) System.out.println(r); } }
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询