源代码:
import java.util.Scanner;
public class addElement {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入需要的数组大小:");
Scanner scan=new Scanner(System.in);
int n = scan.nextInt();//接受输入的数组大小
int[]arr=new int[n];//定义一个大小为刚输入的n的数组
System.out.println("输入数组的每个元素:");
for(int i=0;i
System.out.println("数组的元素依次为:");
for(int i=0;i
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("input your number split by comma:");
String str = input.nextLine();
String arrStr[] = str.split(",");
int arrInt[] = new int[arrStr.length];
for(int i = 0;i
arrInt[i] = a;
}
}
从控制台输入数字,用逗号隔开,可以直接放入数组当中
Object[] array = new Object[10];
for (int i = 0; i < array.length; i++) {
array[i] = new Object();
}
Integer[] array = new Integer[10];
for(int i =0 ;i
}