我在访问for循环外的i
值时遇到问题。起初我想从用户那里得到5个姓名,之后想用数组在屏幕上打印所有的姓名。请帮忙。访问数组索引OutSide For循环
public class Student {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String []Name;
Name=new String[5];
System.out.println("Please Enter The Names Of 5 Students: ");
//INPUTS 5 STUDENTS NAME FROM USER
for(int i=0; i<5; i++)
{
System.out.println("Enter The Name of student: "+(i+1));
Name[i]=input.nextLine();
}
//Prints All The Students Names
System.out.println("The Name of student: "+(i+1)+" is : "+ Name[i]);
}
}
不完全正确:'int [] arr [];'是有效的,给你一个int [] [] – 2012-03-18 07:53:58
@MPlatvoet所以初始类型指定了最小维数? – Dunes 2012-03-18 08:28:02