java - Calling arbitrary number of object instances -


import java.util.*; public class userinput {     public static void main(string[]args){         scanner input = new scanner(system.in);         system.out.println("how many students in class?");         student.n= input.nextint();         for(int i=0; i<student.n; i++){             student = new student(null, null, null, null, 0);         }      } } 

i new java , wondering if it's possible call number of object instances value inputted user during run time. here "n" number of instances want make , thought use method refer variable "i" create new object instance every "i" until reached inputted value of "n". however, duplicate local variable error. wondering if there way around this????

one possible way this:

arraylist<student> manystudents = new arraylist<student>(); for(int i=0; i<student.n; i++){     manystudents.add(new student(null, null, null, null, 0)); } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -