这段代码,是书上的一段代码,我觉得没有任何问题,为什么不能运行呢?
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);
}
}
解决方案 »
- [向ALL]提问...所有学习Java的程序员们..学习
- 请教java解决一个小问题
- sc.nextLine()键盘赋值的问题,请先进来看一下,谢谢
- 抽象类和接口各有什么区别和侧重?
- 关于jTree一点就出错。。。。。
- 菜鸟请教。。。。。。。。。
- 问题一个
- Java用borland的Jbuilder8好还是用sun 的j2sdk 1.4好??
- 高分请教关于提出ResultSet中SUM()值的问题!
- java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
- 一个最简单的java程序,没有任何import 为什么还能System.out.println?谢谢
- 用JDBC操作数据库,高手请进!!!!!!!!!!
函数的初始化? 这句详细的意思怎么回事?
E:\ss\LotteryDrawing.java:33: 找不到符号
符号: 方法 sort(int[])
位置: 类 Arrays
Arrays.sort(result);
^
1 错误处理已完成。
Scanner in=new Scanner(System.in); 是为读取键入数据作调用