第一个程序public static void main(String[] args) {
if (args[0].equals("-h")) // 这里报错
System.out.print("Hello,");
else if (args[0].equals("-g"))
System.out.print("Goodbye");
for (int i = 1; i < args.length; i++)
System.out.print(" " + args[i]);
System.out.print("!");
}第二个程序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(); 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);
}
}
异常和第一个是一样的,就不截图了。

解决方案 »

  1.   

    第一题
    楼主没有传递参数吧
    Eclipse 右击-->run configurations Arguments 在Program arguments里填上几个参数(用空格隔开)
    在dos(黑框)下的话 直接 java Message 参数
      

  2.   

    public static void main(String[] args) {}
    String[] args 是用来接收命令行参数的
    楼主没有传参
    数组里 当然没值
    所以会报错
      

  3.   

    第二题好像没错吧
    How many numbers do you need to draw?这句问你像生成多少个数
    What is the highest number you can draw?问你这些数中的最大数是多少
    然后在后面写上数字(整数)即可
    How many numbers do you need to draw? 5
    What is the highest number you can draw? 7
    Bet the following combination. It'll make you rich!
    1
    2
    3
    5
    7
      

  4.   

    Hello, 
    **************
    How many numbers do you need to draw? 3
    What is the highest number you can draw? 3
    Bet the following combination. It'll make you rich!
    1
    2
    3