日期:2014-05-20  浏览次数:20898 次

有错误,请指点。

import java.util.*;
public class input {

/**
* @100abcnet
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] num = new int[5];// 定义长度为5的int数组
Scanner sc = new Scanner(System.in);// 实例化控制台输入方法

int i,a,b,c;
System.out.println("请输入数..");

for (i = 0; i < num.length; i++) {
num[i] = sc.nextInt();// 循环从控制台输入字符赋值给num数组
}
for (i = 0; i < num.length; i++) {
System.out.print(num[i] + " ");
}
System.out.println("请输入要插入第几位");
a=sc.nextInt();
System.out.println("请输入要插入的数字");
c=sc.nextInt();
for(b=num.length;b>a;b--){
num=num[b-1];
num[a]=c;
}
 
[b]num.length=num.length+1;/++++++说这行the final field array.length cannot be assigned++++++++++++++
 
for (i = 0; i < num.length; i++) {
System.out.print(num[i] + " ");
}
 
}
}

请指教....

------解决方案--------------------
你怎么能改变这个数组的长度呢?
------解决方案--------------------
数组长度不能改变
------解决方案--------------------
数组长度一旦固定就不能改变 如果想改变可以用集合