我想创建一个字符串数组,数组的大小由键盘输入,每个字符串也由键盘输入,我写了这样的代码,怎么一直错误?求大神?
import java.util.Scanner;
public class Example
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int size = reader.nextInt();
String a []= new String [size];
for(int i = 0;i<size;i++)
{
a[i] = reader.nextLine();
}
}
}
import java.util.Scanner;
public class Example
{
public static void main(String[] args)
{
Scanner reader = new Scanner(System.in);
int size = reader.nextInt();
String a []= new String [size];
for(int i = 0;i<size;i++)
{
a[i] = reader.nextLine();
}
}
}