Why can't I pass my arrays?
for (int a = 0;; a++) {
System.out.print("Enter Name:");
name[a] = in.nextLine();
System.out.print("Enter Age:");
age[a] = in.nextInt();
in.nextLine();
Student student = new Student(name[], age[]);
}
The Error says it needs a .class after the arrays Help
Depends on your constructor (ie what it accepts) of Student class, if it accepts array
then
Student student = new Student( name, age); // in this case this line should be after for loop
if it accepts single name and array
then
Student student = new Student( name[a], age[a]);
Why can't I pass my arrays?
because your syntax is incorrect, this here:
Student student = new Student(name[], age[]);
is the reason, to pass an array you normally do
Student student = new Student(name, age);
if you refer to an array in the form of a parameter then you can:
declare a method
void doSomeTricks(String[] args) {
but to call/invoke the method you do
doSomeTricks(myArray);
and not
doSomeTricks(myArray[]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.