这段代码,是书上的一段代码,我觉得没有任何问题,为什么不能运行呢?
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 number you can draw?");
int n=in.nextInt();
//file an array with numbers 1 2 3...n
int[] numbers=new int[n];
for(int i=0;i<numbers.length;i++)
numbers[i]=i+1;
//draw k numbers and put them into a second array
int[] result=new int[k];
for(int i=0;i<result.length;i++){
//make a random index between 0 and n-1;
int r=(int)(Math.random()*n);
//pick the element at the random location
result[i]=numbers[r];
//move the last element into the random location
numbers[r]=numbers[n-1];
n--;
}
//print the sorted array
Arrays.sort(result);
System.out.println("Bet the following combination.It'll make you rich!");
for(int r:result)
System.out.println(r);
}
}
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 number you can draw?");
int n=in.nextInt();
//file an array with numbers 1 2 3...n
int[] numbers=new int[n];
for(int i=0;i<numbers.length;i++)
numbers[i]=i+1;
//draw k numbers and put them into a second array
int[] result=new int[k];
for(int i=0;i<result.length;i++){
//make a random index between 0 and n-1;
int r=(int)(Math.random()*n);
//pick the element at the random location
result[i]=numbers[r];
//move the last element into the random location
numbers[r]=numbers[n-1];
n--;
}
//print the sorted array
Arrays.sort(result);
System.out.println("Bet the following combination.It'll make you rich!");
for(int r:result)
System.out.println(r);
}
}
解决方案 »
- 关于java播放音频文件的问题
- 新手!!苦恼(求指教 不胜感激)
- java SWING的JList,如何使鼠标右键也起选定的作用?
- 谁能告诉我,时钟的算法怎么样实现的,本人算数不怎么好
- 求助jfreechart在solaris下的乱码问题
- switch编译后的lookupswitch 和 tableswitch
- 求教:如何在界面上实现超链接?希望不把ie路径什么的写死,谢谢大家阿
- 想要孙鑫java/VC++完整视频教程的找我
- 困惑!
- 看不懂的一段代码!!!!!!请帮忙!!!!!
- 一个最简单的java程序,没有任何import 为什么还能System.out.println?谢谢
- 用JDBC操作数据库,高手请进!!!!!!!!!!
函数的初始化? 这句详细的意思怎么回事?
E:\ss\LotteryDrawing.java:33: 找不到符号
符号: 方法 sort(int[])
位置: 类 Arrays
Arrays.sort(result);
^
1 错误处理已完成。
Scanner in=new Scanner(System.in); 是为读取键入数据作调用